Created
August 20, 2019 12:19
-
-
Save dasch/afea32a3b0a74f3c131860c2be0dbc27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SqlSchema exposing (..) | |
type SqlType | |
= SqlInt | |
| SqlString | |
type Table = | |
Table { name : String, fields : List FieldSpec } | |
type FieldSpec = | |
FieldSpec { name : String, sqlType : SqlType, options : List SqlOption } | |
type SqlOption | |
= AutoIncrement | |
| NotNull | |
| Null | |
table : String -> List FieldSpec -> Table | |
table = | |
Table | |
field : String -> SqlType -> List SqlOption -> FieldSpec | |
field = | |
FieldSpec | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SqlSchema exposing (table, field, Table, SqlType(..), autoIncrement, notNull) | |
usersTable : Table | |
usersTable = | |
table "users" | |
[ field "id" SqlInt [ autoIncrement ] | |
, field "name" SqlString [ notNull ] | |
, field "email" SqlString [ notNull ] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment