-
Is there some place where I can find some more complex examples on table setup? Things I'm not finding examples for, and struggle figuring out from the reference documentation alone, are
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Thanks to @gasi there’s a fairly complex public example of table setup and migration for ZoomHub |
Beta Was this translation helpful? Give feedback.
-
Here's an example for a table setup with a default uuid primary key and a check constraint spanning more than one column. >>> import Squeal.PostgreSQL
>>> import Squeal.PostgreSQL.UUID.OSSP
>>> :{
type Schema = Public '[
"unit_circle" ::: 'Table (Constraints :=> Columns)]
type Columns = '[
"id" ::: 'Def :=> 'NotNull 'PGuuid,
"x" ::: 'NoDef :=> 'NotNull 'PGfloat8,
"y" ::: 'NoDef :=> 'NotNull 'PGfloat8]
type Constraints = '[
"pk_unit_circle" ::: 'PrimaryKey '["id"],
"length_1" ::: 'Check '["x", "y"]]
:}
>>> :{
let
definition :: Definition (Public '[]) Schema
definition =
createUuidOssp >>>
createTable #unit_circle
( (uuid & notNullable & default_ uuidGenerateV4) `as` #id :*
(float8 & notNullable) `as` #x :*
(float8 & notNullable) `as` #y )
( primaryKey #id `as` #pk_unit_circle :*
check (#x :* #y) (#x * #x + #y * #y .== 1) `as` #length_1
)
:} |
Beta Was this translation helpful? Give feedback.
-
Looks like Squeal is missing this function which wouldn't need the uuid-ossp extension and is apparently a bit faster: genRandomUuid :: Expr (null 'PGuuid)
genRandomUuid = UnsafeExpression "gen_random_uuid()" ^ Just add this to use |
Beta Was this translation helpful? Give feedback.
-
The ZoomHub link did give me several good examples and pointers, but there is one construct I can't figure out how to write: using
|
Beta Was this translation helpful? Give feedback.
Here's an example for a table setup with a default uuid primary key and a check constraint spanning more than one column.