At the moment you need to write the "set-up" function by hands. Though, it mostly duplicates the type definition and translates types into the corresponding functions.
What would be great is to have the function createTables (or any other name) which would do this for you:
createTables :: forall schema . Definition '[] schema
Example
Let's say we have this schema:
type Schema =
'[ "test_users" ::: 'Table
( '[ "pk_users" ::: 'PrimaryKey '["id"] ]
:=> '[ "id" ::: 'Def :=> 'NotNull 'PGint4
, "name" ::: 'NoDef :=> 'NotNull 'PGtext
]
)
]
to setup it now I would need to do the following:
setup :: Definition '[] Schema
setup = createTable #test_users
( serial `as` #id :* (text & notNullable) `as` #name )
( primaryKey #id `as` #pk_users )
If the createTable function would be implemented instead of that you could do just:
setup :: Definition '[] Schema
setup = createTables @Schema
This approach
This is not an uncommon approach. You can see as the example of the servant-client library. client function generates a set of client functions for an API by a given Proxy api:
At the moment you need to write the "set-up" function by hands. Though, it mostly duplicates the type definition and translates types into the corresponding functions.
What would be great is to have the function
createTables(or any other name) which would do this for you:Example
Let's say we have this schema:
to setup it now I would need to do the following:
If the
createTablefunction would be implemented instead of that you could do just:This approach
This is not an uncommon approach. You can see as the example of the
servant-clientlibrary.clientfunction generates a set of client functions for an API by a givenProxy api: