Using SQLite with Graphback
SQLite is an open-source, zero-configuration, self-contained, stand-alone, transaction relational database engine designed to be embedded into an application. Graphback Knex Provider package provides instant integration to your SQLite database, giving you implementation of the CRUD API.
caution
SQLite is a good choice for testing or development purposes. We do not recommend using it in production environment. For a production setup, you can use PostgreSQL.
#
InstallationInstall with npm:
Install with yarn:
#
Configuring the DatabaseThe following code shows how a SQLite database can be configured.
Visit Knex Connection Options to learn more about the different connection options.
#
Using Knex ProviderThe provider exposes a SQLiteKnexDBDataProvider
API, which can be used to create a SQLite data providers for each of your data models.
The code below shows how to create a data provider creator for a SQLite database and how to use it in buildGraphbackAPI
.
The highlighted code does the following:
- Define connection configuration to the database.
- Create a connection to SQLite database using Knex.
- Define the user model.
- Perform the migrations using GraphQL Migrations to create the
user
table. - And finally, create a data provider creator which will be applied to our model, using the
SQLiteKnexDBDataProvider
API.
The rest of the code uses buildGraphbackAPI
to create Graphback CRUD API based on the defined userModel
model.
Visit Data Models to learn more about how to design your business models.