Skip to content

Instantly share code, notes, and snippets.

@dasch
Created August 20, 2019 12:19
Show Gist options
  • Save dasch/afea32a3b0a74f3c131860c2be0dbc27 to your computer and use it in GitHub Desktop.
Save dasch/afea32a3b0a74f3c131860c2be0dbc27 to your computer and use it in GitHub Desktop.
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
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