-
Notifications
You must be signed in to change notification settings - Fork 35
/
Dapper.FSharp.fs
97 lines (82 loc) · 1.94 KB
/
Dapper.FSharp.fs
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
namespace Dapper.FSharp
type OrderDirection =
| Asc
| Desc
type OrderBy = string * OrderDirection
type ColumnComparison =
| Eq of obj
| Ne of obj
| Gt of obj
| Lt of obj
| Ge of obj
| Le of obj
| In of obj list
| NotIn of obj list
| Like of string
| NotLike of string
| IsNull
| IsNotNull
type BinaryOperation =
| And
| Or
type UnaryOperation =
| Not
type Where =
| Empty
| Column of string * ColumnComparison
| Binary of Where * BinaryOperation * Where
| Unary of UnaryOperation * Where
| Expr of string
static member (+) (a, b) = Binary(a, And, b)
static member (*) (a, b) = Binary(a, Or, b)
static member (!!) a = Unary (Not, a)
type Pagination = {
Skip : int
Take : int option
}
type JoinType =
| EqualsToColumn of string
| EqualsToConstant of obj
type Join =
| InnerJoin of table:string * List<string * JoinType>
| LeftJoin of table:string * List<string * JoinType>
module Join =
let tableName = function
| InnerJoin (t, _)
| LeftJoin (t, _) -> t
type Aggregate =
| Count of columnName:string * alias:string
| Avg of columnName:string * alias:string
| Sum of columnName:string * alias:string
| Min of columnName:string * alias:string
| Max of columnName:string * alias:string
type SelectQuery = {
Schema : string option
Table : string
Where : Where
OrderBy : OrderBy list
Pagination : Pagination
Joins : Join list
Aggregates : Aggregate list
GroupBy : string list
Distinct : bool
}
type InsertQuery<'a> = {
Schema : string option
Table : string
Fields : string list
Values : 'a list
}
type UpdateQuery<'a> = {
Schema : string option
Table : string
Value : 'a option
SetColumns: (string * obj) list
Fields : string list
Where : Where
}
type DeleteQuery = {
Schema : string option
Table : string
Where : Where
}