accounts are strings in the client side

This commit is contained in:
Priec
2026-08-08 20:30:57 +02:00
parent 7db328ca2b
commit a7b8d2021a
10 changed files with 69 additions and 81 deletions

View File

@@ -43,6 +43,7 @@ pub const TRAILING_SYSTEM_COLUMNS: [SystemColumn; 1] = [SystemColumn {
/// Its declaration names that profile's schema, so it is built where the
/// profile is known rather than spelled out here.
pub const ACCOUNT_REFERENCE_COLUMN: &str = "account_id";
pub const ACCOUNT_API_COLUMN: &str = "account";
/// Every system column name, whether or not the column is on a given table.
///
@@ -59,12 +60,13 @@ pub fn system_column_names() -> impl Iterator<Item = &'static str> {
/// Whether `name` is a system column: a name that is safe to show a client
/// as-is, and that a user may not claim for a column alias or a table.
pub fn is_system_column(name: &str) -> bool {
system_column_names().any(|system_name| system_name == name)
name == ACCOUNT_API_COLUMN || system_column_names().any(|system_name| system_name == name)
}
/// The system column names in a message, as `'id', 'deleted', ...`.
pub fn system_column_name_list() -> String {
system_column_names()
.chain(std::iter::once(ACCOUNT_API_COLUMN))
.map(|name| format!("'{name}'"))
.collect::<Vec<_>>()
.join(", ")
@@ -73,7 +75,8 @@ pub fn system_column_name_list() -> String {
#[cfg(test)]
mod tests {
use super::{
ACCOUNT_REFERENCE_COLUMN, is_system_column, system_column_name_list, system_column_names,
ACCOUNT_API_COLUMN, ACCOUNT_REFERENCE_COLUMN, is_system_column, system_column_name_list,
system_column_names,
};
#[test]
@@ -86,6 +89,7 @@ mod tests {
#[test]
fn a_conditional_column_is_reserved_on_every_table() {
assert!(is_system_column(ACCOUNT_REFERENCE_COLUMN));
assert!(is_system_column(ACCOUNT_API_COLUMN));
}
#[test]
@@ -98,7 +102,7 @@ mod tests {
fn the_name_list_reads_as_a_sentence_fragment() {
assert_eq!(
system_column_name_list(),
"'id', 'deleted', 'row_revision', 'created_at', 'account_id'"
"'id', 'deleted', 'row_revision', 'created_at', 'account_id', 'account'"
);
}
}