# SQLite (/docs/orm/v6/overview/databases/sqlite)

Location: ORM > v6 > Core Concepts > Supported databases > SQLite

The SQLite data source connector connects Prisma ORM to a [SQLite](https://www.sqlite.org/) database file. These files always have the file ending `.db` (e.g.: `dev.db`).

By default, the SQLite connector contains a database driver responsible for connecting to your database. You can use a [driver adapter](/orm/v6/overview/databases/database-drivers#driver-adapters) (Preview) to connect to your database using a JavaScript database driver from Prisma Client.

Example [#example]

To connect to a SQLite database file, you need to configure a [`datasource`](/orm/v6/prisma-schema/overview/data-sources) block in your [Prisma schema](/orm/v6/prisma-schema/overview):

```prisma title="schema.prisma"
datasource db {
  provider = "sqlite"
}
```

The `datasource` block specifies the `sqlite` data source connector.

In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/v6/reference/prisma-config-reference):

```typescript title="prisma.config.ts"
import { defineConfig } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  datasource: {
    url: "file:./dev.db",
  },
});
```

The connection URL always starts with the prefix `file:` and then contains a file path pointing to the SQLite database file. In this example, the file is located in the same directory and called `dev.db`.

Using the better-sqlite3 driver [#using-the-better-sqlite3-driver]

As of [`v5.4.0`](https://github.com/prisma/prisma/releases/tag/5.4.0), you can use Prisma ORM with database drivers from the JavaScript ecosystem (instead of using Prisma ORM's built-in drivers). You can do this by using a [driver adapter](/orm/v6/overview/databases/database-drivers).

For SQLite, [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3) is one of the most popular drivers in the JavaScript ecosystem.

This section explains how you can use it with Prisma ORM and the `@prisma/adapter-better-sqlite3` driver adapter.

1. Install the dependencies [#1-install-the-dependencies]

First, install Prisma ORM's driver adapter for `better-sqlite3`:

  

#### npm

```bash
npm install @prisma/adapter-better-sqlite3
```

#### pnpm

```bash
pnpm add @prisma/adapter-better-sqlite3
```

#### yarn

```bash
yarn add @prisma/adapter-better-sqlite3
```

#### bun

```bash
bun add @prisma/adapter-better-sqlite3
```

2. Instantiate Prisma Client using the driver adapter [#2-instantiate-prisma-client-using-the-driver-adapter]

Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor:

```ts
import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3";
import { PrismaClient } from "./generated/prisma";

const adapter = new PrismaBetterSqlite3({
  url: "file:./prisma/dev.db",
});
const prisma = new PrismaClient({ adapter });
```

> [!NOTE]
> Using SQLite with Bun
> 
> When running Prisma Client on Bun, use the `@prisma/adapter-libsql` driver adapter. Bun doesn't support the native SQLite driver that `better-sqlite3` relies on (see the [`node:sqlite` reference](https://bun.com/reference/node/sqlite)). Instantiate the adapter and pass it to `PrismaClient`:
> 
> ```ts
> import { PrismaClient } from "../prisma/generated/client";
> import { PrismaLibSql } from "@prisma/adapter-libsql";
> 
> const adapter = new PrismaLibSql({
>   url: process.env.DATABASE_URL ?? "",
> });
> 
> const prisma = new PrismaClient({ adapter });
> 
> export default prisma;
> ```

3. Configure timestamp format for backward compatibility [#3-configure-timestamp-format-for-backward-compatibility]

When using driver adapters with SQLite, you can configure how `DateTime` values are stored in the database using the `timestampFormat` option.

By default, driver adapters store `DateTime` values as **ISO 8601 strings**, which is the most convenient format for SQLite since SQLite date/time functions expect ISO 8601 by default.

However, if you need **100% backward compatibility** with Prisma ORM's native SQLite driver (for example, when migrating an existing database), you should use the `unixepoch-ms` format, which stores timestamps as the number of milliseconds since the Unix epoch:

```ts
import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3";
import { PrismaClient } from "./generated/prisma";

const adapter = new PrismaBetterSqlite3(
  {
    url: "file:./prisma/dev.db",
  },
  {
    timestampFormat: "unixepoch-ms",
  },
);
const prisma = new PrismaClient({ adapter });
```

> [!NOTE]
> The `timestampFormat` option is available for both `@prisma/adapter-better-sqlite3` and `@prisma/adapter-libsql` driver adapters.

**When to use each format:**

* **ISO 8601 (default)**: Best for new projects and integrates well with SQLite's built-in date/time functions.
* **`unixepoch-ms`**: Required when migrating from Prisma ORM's native SQLite driver to maintain compatibility with existing timestamp data.

Type mapping between SQLite to Prisma schema [#type-mapping-between-sqlite-to-prisma-schema]

The SQLite connector maps the [scalar types](/orm/v6/prisma-schema/data-model/models#scalar-fields) from the [data model](/orm/v6/prisma-schema/data-model/models) to native column types as follows:

> Alternatively, see [Prisma schema reference](/orm/v6/reference/prisma-schema-reference#model-field-scalar-types) for type mappings organized by Prisma ORM type.

Native type mapping from Prisma ORM to SQLite [#native-type-mapping-from-prisma-orm-to-sqlite]

| Prisma ORM | SQLite    |
| ---------- | --------- |
| `String`   | `TEXT`    |
| `Boolean`  | `BOOLEAN` |
| `Int`      | `INTEGER` |
| `BigInt`   | `INTEGER` |
| `Float`    | `REAL`    |
| `Decimal`  | `DECIMAL` |
| `DateTime` | `NUMERIC` |
| `Json`     | `JSONB`   |
| `Bytes`    | `BLOB`    |
| `Enum`     | `TEXT`    |

> [!NOTE]
> SQLite doesn't have a dedicated Boolean type. While this table shows `BOOLEAN`, columns are assigned a **NUMERIC affinity** (storing `0` for false and `1` for true). [Learn more](https://www.sqlite.org/datatype3.html#boolean).

> [!WARNING]
> When using `enum` fields in SQLite, be aware of the following:
> 
> * **No database-level enforcement for correctness**: If you bypass Prisma ORM and store an invalid enum entry in the database, Prisma Client queries will fail at runtime when reading that entry.
> * **No migration-level enforcement for correctness**: It's possible to end up with incorrect data after schema changes similarly to MongoDB (since the enums aren't checked by the database).

Rounding errors on big numbers [#rounding-errors-on-big-numbers]

SQLite is a loosely-typed database. If your Schema has a field of type `Int`, then Prisma ORM prevents you from inserting a value larger than an integer. However, nothing prevents the database from directly accepting a bigger number. These manually-inserted big numbers cause rounding errors when queried.

To avoid this problem, Prisma ORM 4.0.0 and later checks numbers on the way out of the database to verify that they fit within the boundaries of an integer. If a number does not fit, then Prisma ORM throws a P2023 error, such as:

```
Inconsistent column data: Conversion failed:
Value 9223372036854775807 does not fit in an INT column,
try migrating the 'int' column type to BIGINT
```

Connection details [#connection-details]

Connection URL [#connection-url]

The connection URL of a SQLite connector points to a file on your file system and is configured in `prisma.config.ts`. For example, the following two paths are equivalent because the `.db` is in the same directory:

```typescript title="prisma.config.ts"
datasource: {
  url: 'file:./dev.db',
}
```

is the same as:

```typescript title="prisma.config.ts"
datasource: {
  url: 'file:dev.db',
}
```

You can also target files from the root or any other place in your file system:

```typescript title="prisma.config.ts"
datasource: {
  url: 'file:/Users/janedoe/dev.db',
}
```

## Related pages

- [`Cloudflare D1`](https://www.prisma.io/docs/orm/v6/overview/databases/cloudflare-d1): Guide to Cloudflare D1
- [`CockroachDB`](https://www.prisma.io/docs/orm/v6/overview/databases/cockroachdb): Guide to CockroachDB
- [`Database drivers`](https://www.prisma.io/docs/orm/v6/overview/databases/database-drivers): Learn how Prisma connects to your database using the built-in drivers and how you can use Prisma along with other JavaScript database drivers using driver adapters (Preview)
- [`Microsoft SQL Server`](https://www.prisma.io/docs/orm/v6/overview/databases/sql-server): This page explains how Prisma can connect to a Microsoft SQL Server database using the Microsoft SQL Server database connector.
- [`MySQL/MariaDB`](https://www.prisma.io/docs/orm/v6/overview/databases/mysql): This page explains how Prisma can connect to a MySQL or MariaDB database using the MySQL database connector.