From 258eabff54d985c69949531b09742c3c077406f4 Mon Sep 17 00:00:00 2001 From: ZacJW Date: Mon, 16 Jun 2025 07:54:32 +0100 Subject: [PATCH] Refactor database types --- rasql-core/src/sql.rs | 56 ++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/rasql-core/src/sql.rs b/rasql-core/src/sql.rs index cb925eb..0ab00b3 100644 --- a/rasql-core/src/sql.rs +++ b/rasql-core/src/sql.rs @@ -29,7 +29,7 @@ pub fn parse_sql_schema( let schema = schema_for_object(&mut schemas, &name); schema.types.insert( name.clone(), - Type::Composite { + UserDefinedType::Composite(CompositeType { name: name.clone(), fields: columns .iter() @@ -38,7 +38,7 @@ pub fn parse_sql_schema( r#type: column.data_type.clone(), }) .collect(), - }, + }), ); schema.tables.insert( name.clone(), @@ -73,7 +73,7 @@ pub fn parse_sql_schema( let schema = schema_for_object(&mut schemas, &name); schema.types.insert( name.clone(), - Type::Composite { + UserDefinedType::Composite(CompositeType { name, fields: attributes .into_iter() @@ -82,7 +82,7 @@ pub fn parse_sql_schema( r#type: attr.data_type, }) .collect(), - }, + }), ); } sqlparser::ast::Statement::CreateType { @@ -92,10 +92,10 @@ pub fn parse_sql_schema( let schema = schema_for_object(&mut schemas, &name); schema.types.insert( name.clone(), - Type::Enum { + UserDefinedType::Enum(EnumType { name, variants: labels, - }, + }), ); } _ => (), @@ -143,7 +143,7 @@ fn schema_for_object<'a>( pub struct Schema { pub name: SchemaName, pub tables: HashMap, - pub types: HashMap, + pub types: HashMap, } pub struct Table { @@ -152,18 +152,42 @@ pub struct Table { pub constraints: Vec, } -pub enum Type { - Composite { - name: ObjectName, - fields: Vec, - }, - Enum { - name: ObjectName, - variants: Vec, - }, +pub enum UserDefinedType { + Composite(CompositeType), + Enum(EnumType), + Domain(DomainType), +} + +pub struct CompositeType { + name: ObjectName, + fields: Vec, +} + +pub struct EnumType { + name: ObjectName, + variants: Vec, +} + +pub struct DomainType { + } pub struct Field { pub name: Ident, pub r#type: DataType, } + +pub enum Constraint { + PrimaryKey(PrimaryKeyConstraint), + ForeignKey(ForeignKeyConstraint), + Unique(UniqueConstraint), + Check(CheckConstraint), +} + +pub struct PrimaryKeyConstraint {} + +pub struct ForeignKeyConstraint {} + +pub struct UniqueConstraint {} + +pub struct CheckConstraint {}