|
| 1 | +--- |
| 2 | +title: SQLite |
| 3 | +label: SQLite |
| 4 | +order: 60 |
| 5 | +desc: Payload supports SQLite through an officially supported Drizzle Database Adapter. |
| 6 | +keywords: SQLite, documentation, typescript, Content Management System, cms, headless, javascript, node, react, nextjs |
| 7 | +--- |
| 8 | + |
| 9 | +To use Payload with SQLite, install the package `@payloadcms/db-sqlite`. It leverages Drizzle ORM and `libSQL` to interact with a SQLite database that you provide. |
| 10 | + |
| 11 | +It automatically manages changes to your database for you in development mode, and exposes a full suite of migration controls for you to leverage in order to keep other database environments in sync with your schema. DDL transformations are automatically generated. |
| 12 | + |
| 13 | +To configure Payload to use SQLite, pass the `sqliteAdapter` to your Payload Config as follows: |
| 14 | + |
| 15 | +```ts |
| 16 | +import { sqliteAdapter } from '@payloadcms/db-sqlite' |
| 17 | + |
| 18 | +export default buildConfig({ |
| 19 | + // Your config goes here |
| 20 | + collections: [ |
| 21 | + // Collections go here |
| 22 | + ], |
| 23 | + // Configure the SQLite adapter here |
| 24 | + db: sqliteAdapter({ |
| 25 | + // SQLite-specific arguments go here. |
| 26 | + // `client.url` is required. |
| 27 | + client: { |
| 28 | + url: process.env.DATABASE_URL, |
| 29 | + authToken: process.env.DATABASE_AUTH_TOKEN, |
| 30 | + } |
| 31 | + }), |
| 32 | +}) |
| 33 | +``` |
| 34 | + |
| 35 | +## Options |
| 36 | + |
| 37 | +| Option | Description | |
| 38 | +|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 39 | +| `client` \* | [Client connection options](https://orm.drizzle.team/docs/get-started-sqlite#turso) that will be passed to `createClient` from `@libsql/client`. | |
| 40 | +| `push` | Disable Drizzle's [`db push`](https://orm.drizzle.team/kit-docs/overview#prototyping-with-db-push) in development mode. By default, `push` is enabled for development mode only. | |
| 41 | +| `migrationDir` | Customize the directory that migrations are stored. | |
| 42 | +| `logger` | The instance of the logger to be passed to drizzle. By default Payload's will be used. | |
| 43 | +| `transactionOptions` | A SQLiteTransactionConfig object for transactions, or set to `false` to disable using transactions. [More details](https://orm.drizzle.team/docs/transactions) | |
| 44 | +| `localesSuffix` | A string appended to the end of table names for storing localized fields. Default is '_locales'. | |
| 45 | +| `relationshipsSuffix` | A string appended to the end of table names for storing relationships. Default is '_rels'. | |
| 46 | +| `versionsSuffix` | A string appended to the end of table names for storing versions. Defaults to '_v'. | |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +## Access to Drizzle |
| 51 | + |
| 52 | +After Payload is initialized, this adapter will expose the full power of Drizzle to you for use if you need it. |
| 53 | + |
| 54 | +You can access Drizzle as follows: |
| 55 | + |
| 56 | +```text |
| 57 | +payload.db.drizzle |
| 58 | +``` |
| 59 | + |
| 60 | +## Tables and relations |
| 61 | + |
| 62 | +In addition to exposing Drizzle directly, all of the tables and Drizzle relations are exposed for you via the `payload.db` property as well. |
| 63 | + |
| 64 | +- Tables - `payload.db.tables` |
| 65 | +- Relations - `payload.db.relations` |
| 66 | + |
| 67 | +## Prototyping in development mode |
| 68 | + |
| 69 | +Drizzle exposes two ways to work locally in development mode. |
| 70 | + |
| 71 | +The first is [`db push`](https://orm.drizzle.team/kit-docs/overview#prototyping-with-db-push), which automatically pushes changes you make to your Payload Config (and therefore, Drizzle schema) to your database so you don't have to manually migrate every time you change your Payload Config. This only works in development mode, and should not be mixed with manually running [`migrate`](/docs/database/migrations) commands. |
| 72 | + |
| 73 | +You will be warned if any changes that you make will entail data loss while in development mode. Push is enabled by default, but you can opt out if you'd like. |
| 74 | + |
| 75 | +Alternatively, you can disable `push` and rely solely on migrations to keep your local database in sync with your Payload Config. |
| 76 | + |
| 77 | +## Migration workflows |
| 78 | + |
| 79 | +In SQLite, migrations are a fundamental aspect of working with Payload and you should become familiar with how they work. |
| 80 | + |
| 81 | +For more information about migrations, [click here](/docs/beta/database/migrations#when-to-run-migrations). |
0 commit comments