Refactor database types
This commit is contained in:
parent
9eb02a767b
commit
258eabff54
1 changed files with 40 additions and 16 deletions
|
|
@ -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<ObjectName, Table>,
|
||||
pub types: HashMap<ObjectName, Type>,
|
||||
pub types: HashMap<ObjectName, UserDefinedType>,
|
||||
}
|
||||
|
||||
pub struct Table {
|
||||
|
|
@ -152,18 +152,42 @@ pub struct Table {
|
|||
pub constraints: Vec<TableConstraint>,
|
||||
}
|
||||
|
||||
pub enum Type {
|
||||
Composite {
|
||||
name: ObjectName,
|
||||
fields: Vec<Field>,
|
||||
},
|
||||
Enum {
|
||||
name: ObjectName,
|
||||
variants: Vec<Ident>,
|
||||
},
|
||||
pub enum UserDefinedType {
|
||||
Composite(CompositeType),
|
||||
Enum(EnumType),
|
||||
Domain(DomainType),
|
||||
}
|
||||
|
||||
pub struct CompositeType {
|
||||
name: ObjectName,
|
||||
fields: Vec<Field>,
|
||||
}
|
||||
|
||||
pub struct EnumType {
|
||||
name: ObjectName,
|
||||
variants: Vec<Ident>,
|
||||
}
|
||||
|
||||
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 {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue