You will also need to install the appropriate driver for your database
- PostgreSQL 9.4+
- MySQL 8.0+
- MariaDB 10.2.3+
- SQLite 3.9.0+ (with json1 extension)
Define your models
Start by writing your type definitions. Add the
@sqlmancer directive to provide any configuration options to the database client. Then, use the
@model directive to define your data models right in your schema.
Read more about defining models here.
Create the database client
Sqlmancer uses Knex under the hood and requires a Knex instance to initialize a new client instance. You can read more about configuring Knex here. Pass the Knex instance and a glob pattern string matching the location of your type definitions to
createSqlmancerClient. Your type definitions can be
If you're using TypeScript, you can generate a type for your client instance using the CLI. This will enable complete typings for both the client methods as well as the results they return.
Use the client
Sqlmancer will parse the
GraphQLResolveInfo object passed to it to determine which columns to select and which associations to load. Read more about the methods available for each model here.
Create your schema
In order to utilize Sqlmancer's schema directives, you need to add them to your schema.
makeSqlmancerSchema is a convenient wrapper around
makeExecutableSchema that does this for you:
If you prefer to add the directives yourself, you may do so as well: