forked from fsprojects/Rezoom.SQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.fs
More file actions
104 lines (89 loc) · 2.76 KB
/
Model.fs
File metadata and controls
104 lines (89 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
namespace Rezoom.SQL.Compiler
open System.Collections.Generic
[<NoComparison>]
type DatabaseBuiltin =
{ Functions : Map<Name, FunctionType>
}
type QualifiedObjectName =
{ SchemaName : Name
ObjectName : Name
}
override this.ToString() =
this.SchemaName.Value + "." + this.ObjectName.Value
type BackendCharacteristics =
{ CanDropColumnWithDefaultValue : bool
}
[<NoComparison>]
type Model =
{ Schemas : Map<Name, Schema>
DefaultSchema : Name
TemporarySchema : Name
Builtin : DatabaseBuiltin
BackendCharacteristics : BackendCharacteristics
}
member this.Schema(name : Name option) =
this.Schemas |> Map.tryFind (name |? this.DefaultSchema)
and [<NoComparison>] Schema =
{ SchemaName : Name
Objects : Map<Name, SchemaObject>
}
static member Empty(name) =
{ SchemaName = name
Objects = Map.empty
}
member this.ContainsObject(name : Name) = this.Objects.ContainsKey(name)
and [<NoComparison>] SchemaObject =
| SchemaTable of SchemaTable
| SchemaView of SchemaView
| SchemaIndex of SchemaIndex
| SchemaConstraint of SchemaConstraint
and SchemaIndex =
{ TableName : QualifiedObjectName
IndexName : Name
Columns : Name Set
}
and SchemaForeignKey =
{ ToTable : QualifiedObjectName
ToColumns : Name Set
OnDelete : OnDeleteAction option
}
and SchemaConstraintType =
| PrimaryKeyConstraintType of auto : bool
| ForeignKeyConstraintType of SchemaForeignKey
| CheckConstraintType
| UniqueConstraintType
and SchemaConstraint =
{ ConstraintType : SchemaConstraintType
TableName : QualifiedObjectName
ConstraintName : Name
/// Which columns this constraint relates to in the table.
Columns : Name Set
}
and SchemaReverseForeignKey =
{ FromTable : QualifiedObjectName
FromConstraint : Name
OnDelete : OnDeleteAction option
}
and [<NoComparison>] SchemaTable =
{ Name : QualifiedObjectName
Columns : Map<Name, SchemaColumn>
Indexes : Map<Name, SchemaIndex>
Constraints : Map<Name, SchemaConstraint>
ReverseForeignKeys : SchemaReverseForeignKey Set
}
and [<NoComparison>] SchemaColumn =
{ TableName : QualifiedObjectName
ColumnName : Name
/// True if this column is part of the table's primary key.
PrimaryKey : bool
DefaultValue : Expr option
ColumnType : ColumnType
ColumnTypeName : TypeName
Collation : Name option
}
and [<NoComparison>] SchemaView =
{ SchemaName : Name
ViewName : Name
CreateDefinition : CreateViewStmt
}
member this.Definition = this.CreateDefinition.AsSelect