Skip to content

Instantly share code, notes, and snippets.

@dasch
Created Aug 20, 2019
Embed
What would you like to do?
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