pub trait TypedTable: 'static {
const NAME: &'static str;
}
pub trait TypedColumn: 'static {
const NAME: &'static str;
type Table: TypedTable;
type RustType;
type SqlType: crate::typed_ast::SqlType;
}
pub const fn _schema_lookup(_schema: &[(&str, &str)], _col: &str) -> Option<&'static str> {
None
}
#[cfg(test)]
mod tests {
use super::*;
struct MockUsersTable;
impl TypedTable for MockUsersTable {
const NAME: &'static str = "users";
}
struct MockColId;
impl TypedColumn for MockColId {
const NAME: &'static str = "id";
type Table = MockUsersTable;
type RustType = i64;
type SqlType = crate::typed_ast::Untyped;
}
struct MockColName;
impl TypedColumn for MockColName {
const NAME: &'static str = "name";
type Table = MockUsersTable;
type RustType = String;
type SqlType = crate::typed_ast::Untyped;
}
#[test]
fn test_typed_table_name() {
assert_eq!(MockUsersTable::NAME, "users");
}
#[test]
fn test_typed_column_name() {
assert_eq!(MockColId::NAME, "id");
assert_eq!(MockColName::NAME, "name");
}
#[test]
fn test_typed_column_table_association() {
fn _assert_table<T: TypedColumn<Table = MockUsersTable>>(_: T) {}
_assert_table(MockColId);
_assert_table(MockColName);
}
#[test]
fn test_typed_column_rust_type() {
fn _assert_type<T: TypedColumn<RustType = i64>>(_: T) {}
_assert_type(MockColId);
fn _assert_string_type<T: TypedColumn<RustType = String>>(_: T) {}
_assert_string_type(MockColName);
}
#[test]
fn test_zero_sized_types() {
assert_eq!(std::mem::size_of::<MockUsersTable>(), 0);
assert_eq!(std::mem::size_of::<MockColId>(), 0);
assert_eq!(std::mem::size_of::<MockColName>(), 0);
}
#[test]
fn test_schema_lookup_returns_none() {
let schema: &[(&str, &str)] = &[("id", "i64"), ("name", "String")];
assert_eq!(_schema_lookup(schema, "id"), None);
}
}