Skip to content

Commit b28b225

Browse files
docs: document QE timestamp backward compatibility (#7187)
Co-authored-by: Ankur Datta <[email protected]>
1 parent d3857e7 commit b28b225

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

content/200-orm/050-overview/500-databases/500-sqlite.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,37 @@ const adapter = new PrismaBetterSQLite3({
5555
const prisma = new PrismaClient({ adapter });
5656
```
5757

58+
### 3. Configure timestamp format for backward compatibility
59+
60+
When using driver adapters with SQLite, you can configure how `DateTime` values are stored in the database using the `timestampFormat` option.
61+
62+
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.
63+
64+
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:
65+
66+
```ts
67+
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
68+
import { PrismaClient } from './generated/prisma';
69+
70+
const adapter = new PrismaBetterSQLite3({
71+
url: "file:./prisma/dev.db"
72+
}, {
73+
timestampFormat: 'unixepoch-ms'
74+
});
75+
const prisma = new PrismaClient({ adapter });
76+
```
77+
78+
:::info
79+
80+
The `timestampFormat` option is available for both `@prisma/adapter-better-sqlite3` and `@prisma/adapter-libsql` driver adapters.
81+
82+
:::
83+
84+
**When to use each format:**
85+
86+
- **ISO 8601 (default)**: Best for new projects and integrates well with SQLite's built-in date/time functions.
87+
- **`unixepoch-ms`**: Required when migrating from Prisma ORM's native SQLite driver to maintain compatibility with existing timestamp data.
88+
5889
## Type mapping between SQLite to Prisma schema
5990

6091
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:

0 commit comments

Comments
 (0)