From 959457a90d83e34c79eaa18436576499b2e7d8b6 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Tue, 14 Oct 2025 17:01:19 +0530 Subject: [PATCH 1/2] docs: document QE timestamp backward compatibility (better-sqlite3, libSQL) --- .../050-overview/500-databases/500-sqlite.mdx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/content/200-orm/050-overview/500-databases/500-sqlite.mdx b/content/200-orm/050-overview/500-databases/500-sqlite.mdx index 8b869093f9..bb870b0c03 100644 --- a/content/200-orm/050-overview/500-databases/500-sqlite.mdx +++ b/content/200-orm/050-overview/500-databases/500-sqlite.mdx @@ -55,6 +55,37 @@ const adapter = new PrismaBetterSQLite3({ const prisma = new PrismaClient({ adapter }); ``` +### 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 }); +``` + +:::info + +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. Works seamlessly 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 The SQLite connector maps the [scalar types](/orm/prisma-schema/data-model/models#scalar-fields) from the [data model](/orm/prisma-schema/data-model/models) to native column types as follows: From 0c7b69ffb0659f04fd0678b3900824785a77d5fe Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Tue, 14 Oct 2025 17:47:39 +0530 Subject: [PATCH 2/2] Update content/200-orm/050-overview/500-databases/500-sqlite.mdx Co-authored-by: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> --- content/200-orm/050-overview/500-databases/500-sqlite.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/200-orm/050-overview/500-databases/500-sqlite.mdx b/content/200-orm/050-overview/500-databases/500-sqlite.mdx index bb870b0c03..db904f7aa8 100644 --- a/content/200-orm/050-overview/500-databases/500-sqlite.mdx +++ b/content/200-orm/050-overview/500-databases/500-sqlite.mdx @@ -83,7 +83,7 @@ The `timestampFormat` option is available for both `@prisma/adapter-better-sqlit **When to use each format:** -- **ISO 8601 (default)**: Best for new projects. Works seamlessly with SQLite's built-in date/time functions. +- **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