Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6652608
move sqlite logic to the drizzle package
r1tsuu May 24, 2025
f51c972
add exports from drizzle
r1tsuu May 24, 2025
0829cfb
fix imports
r1tsuu May 24, 2025
52f9dca
finish d1 package and fix errors
r1tsuu May 26, 2025
da4270f
sqlOnly migrations
r1tsuu May 26, 2025
9bd5f6f
try testing
r1tsuu May 26, 2025
733594b
fix package jason
r1tsuu May 26, 2025
5de2f52
fix vercel postgres build
r1tsuu May 26, 2025
fd850e7
fix postgres build
r1tsuu May 26, 2025
c3af32e
fix postgres build 2
r1tsuu May 26, 2025
be4f11c
Merge branch 'main' of github.com:payloadcms/payload into feat/add-d1…
r1tsuu Jul 23, 2025
9ce07c7
fix type
r1tsuu Jul 23, 2025
8595b57
fix type
r1tsuu Jul 23, 2025
3d57b06
Merge branch 'main' of github.com:payloadcms/payload into feat/add-d1…
r1tsuu Jul 23, 2025
65b110e
fix type
r1tsuu Jul 23, 2025
3f09e27
execute method
r1tsuu Jul 25, 2025
9201051
storage r2
r1tsuu Jul 28, 2025
72fbcc3
Merge branch 'main' of github.com:payloadcms/payload into feat/add-d1…
r1tsuu Jul 28, 2025
759bb98
change version
r1tsuu Jul 28, 2025
fb19606
delete :memory
r1tsuu Jul 28, 2025
f87db1c
add r2 and d1 to publishList in script
paulpopus Jul 28, 2025
ca62628
empty commit for new hash
paulpopus Jul 30, 2025
f95bba4
Merge branch 'main' of github.com:payloadcms/payload into feat/add-d1…
r1tsuu Sep 25, 2025
3291d84
add sqlite to test package json
r1tsuu Sep 25, 2025
df9fce5
changes to d1 package
paulpopus Sep 26, 2025
8916aea
remove sqlOnly
paulpopus Sep 29, 2025
b88cbd7
remove miniflare/d1 dep as its deprecated
paulpopus Sep 29, 2025
8775d75
commit lock file
paulpopus Sep 29, 2025
224d7a2
update package.json for adapter
paulpopus Sep 29, 2025
618a991
add template
paulpopus Sep 29, 2025
642d1a0
update pack all to dest
paulpopus Sep 29, 2025
4154be2
update lock file
paulpopus Sep 29, 2025
d2a3f22
add to setupProd
paulpopus Sep 29, 2025
7dcf69e
remove as any
paulpopus Sep 29, 2025
bc94fac
add docs and updated readme
paulpopus Sep 29, 2025
3ea6ede
add link to issue
paulpopus Sep 29, 2025
91eaf61
update docs with beta warning and readme
paulpopus Sep 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/database/sqlite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,35 @@ sqliteAdapter({
],
})
```

## D1 Database

<Banner type="warning">
This adapter is currently in beta as it is new and could be subject to changes
which may be considered breaking
</Banner>

We also provide a separate adapter to connect to [Cloudflare D1](https://developers.cloudflare.com/d1/), which is a serverless SQLite database.

To use it, install the package `@payloadcms/db-d1-sqlite` and configure it as follows:

```ts
import { sqliteD1Adapter } from '@payloadcms/db-d1-sqlite'

export default buildConfig({
// Your config goes here
collections: [
// Collections go here
],
// Configure the D1 adapter here
db: sqliteD1Adapter({
// D1-specific arguments go here.
// `binding` is required and should match the D1 database binding name in your Cloudflare Worker environment.
binding: cloudflare.env.D1,
}),
})
```

It inherits the options from the SQLite adapter above with the exception of the connection options in favour of the `binding`.

You can see our [Cloudflare D1 template](https://github.com/payloadcms/payload/tree/main/templates/with-cloudflare-d1) for a full example of how to set this up.
38 changes: 38 additions & 0 deletions docs/upload/storage-adapters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Payload offers additional storage adapters to handle file uploads. These adapter
| Azure | [`@payloadcms/storage-azure`](https://github.com/payloadcms/payload/tree/main/packages/storage-azure) |
| Google Cloud Storage | [`@payloadcms/storage-gcs`](https://github.com/payloadcms/payload/tree/main/packages/storage-gcs) |
| Uploadthing | [`@payloadcms/storage-uploadthing`](https://github.com/payloadcms/payload/tree/main/packages/storage-uploadthing) |
| R2 | [`@payloadcms/storage-r2`](https://github.com/payloadcms/payload/tree/main/packages/storage-r2) |

## Vercel Blob Storage

Expand Down Expand Up @@ -277,6 +278,43 @@ export default buildConfig({
| `defaultKeyType` | Default key type for file operations | `fileKey` |
| `clientUploads` | Do uploads directly on the client to bypass limits on Vercel. | |

## R2 Storage

<Banner type="warning">
**Note**: The R2 Storage Adapter is in **beta** as some aspects of it may
change on any minor releases.
</Banner>

[`@payloadcms/storage-r2`](https://www.npmjs.com/package/@payloadcms/storage-r2)

Use this adapter to store uploads in a Cloudflare R2 bucket via the Cloudflare Workers environment. If you're trying to connect to R2 using the S3 API then you should use the [S3](#s3-storage) adapter instead.

### Installation#r2-installation

```sh
pnpm add @payloadcms/storage-r2
```

### Usage#r2-usage

- Configure the `collections` object to specify which collections should use r2. The slug _must_ match one of your existing collection slugs and be an `upload` type.
- Pass in the R2 bucket binding to the `bucket` option, this should be done in the environment where Payload is running (e.g. Cloudflare Worker).
- You can conditionally datamine whether or not to enable the plugin with the `enabled` option.

```ts
export default buildConfig({
collections: [Media],
plugins: [
r2Storage({
collections: {
media: true,
},
bucket: cloudflare.env.R2,
}),
],
})
```

## Custom Storage Adapters

If you need to create a custom storage adapter, you can use the [`@payloadcms/plugin-cloud-storage`](https://www.npmjs.com/package/@payloadcms/plugin-cloud-storage) package. This package is used internally by the storage adapters mentioned above.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"build:core": "turbo build --filter \"!@payloadcms/plugin-*\" --filter \"!@payloadcms/storage-*\" --filter \"!blank\" --filter \"!website\"",
"build:core:force": "pnpm clean:build && pnpm build:core --no-cache --force",
"build:create-payload-app": "turbo build --filter create-payload-app",
"build:db-d1-sqlite": "turbo build --filter \"@payloadcms/db-d1-sqlite\"",
"build:db-mongodb": "turbo build --filter \"@payloadcms/db-mongodb\"",
"build:db-postgres": "turbo build --filter \"@payloadcms/db-postgres\"",
"build:db-sqlite": "turbo build --filter \"@payloadcms/db-sqlite\"",
Expand Down
1 change: 1 addition & 0 deletions packages/db-d1-sqlite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/migrations
10 changes: 10 additions & 0 deletions packages/db-d1-sqlite/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.tmp
**/.git
**/.hg
**/.pnp.*
**/.svn
**/.yarn/**
**/build
**/dist/**
**/node_modules
**/temp
15 changes: 15 additions & 0 deletions packages/db-d1-sqlite/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"sourceMaps": true,
"jsc": {
"target": "esnext",
"parser": {
"syntax": "typescript",
"tsx": true,
"dts": true
}
},
"module": {
"type": "es6"
}
}
22 changes: 22 additions & 0 deletions packages/db-d1-sqlite/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2018-2025 Payload CMS, Inc. <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 changes: 33 additions & 0 deletions packages/db-d1-sqlite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Payload D1 SQLite Adapter

Official D1 SQLite adapter for [Payload](https://payloadcms.com).

- [Main Repository](https://github.com/payloadcms/payload)
- [Payload Docs](https://payloadcms.com/docs)

## Installation

```bash
npm install @payloadcms/db-d1-sqlite
```

## Usage

```ts
import { sqliteD1Adapter } from '@payloadcms/db-d1-sqlite'

export default buildConfig({
// Your config goes here
collections: [
// Collections go here
],
// Configure the D1 adapter here
db: sqliteD1Adapter({
// D1-specific arguments go here.
// `binding` is required and should match the D1 database binding name in your Cloudflare Worker environment.
binding: cloudflare.env.D1,
}),
})
```

More detailed usage can be found in the [Payload Docs](https://payloadcms.com/docs/database/sqlite).
38 changes: 38 additions & 0 deletions packages/db-d1-sqlite/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as esbuild from 'esbuild'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
import { commonjs } from '@hyrious/esbuild-plugin-commonjs'

async function build() {
const resultServer = await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
platform: 'node',
format: 'esm',
outfile: 'dist/index.js',
splitting: false,
external: [
'*.scss',
'*.css',
'drizzle-kit',
'libsql',
'pg',
'@payloadcms/translations',
'@payloadcms/drizzle',
'payload',
'payload/*',
],
minify: true,
metafile: true,
tsconfig: path.resolve(dirname, './tsconfig.json'),
plugins: [commonjs()],
sourcemap: true,
})
console.log('db-sqlite bundled successfully')

fs.writeFileSync('meta_server.json', JSON.stringify(resultServer.metafile))
}
await build()
134 changes: 134 additions & 0 deletions packages/db-d1-sqlite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"name": "@payloadcms/db-d1-sqlite",
"version": "3.57.0",
"description": "The officially supported D1 SQLite database adapter for Payload",
"homepage": "https://payloadcms.com",
"repository": {
"type": "git",
"url": "https://github.com/payloadcms/payload.git",
"directory": "packages/db-d1-sqlite"
},
"license": "MIT",
"author": "Payload <[email protected]> (https://payloadcms.com)",
"maintainers": [
{
"name": "Payload",
"email": "[email protected]",
"url": "https://payloadcms.com"
}
],
"type": "module",
"exports": {
".": {
"import": "./src/index.ts",
"require": "./src/index.ts",
"types": "./src/index.ts"
},
"./types": {
"import": "./src/exports/types-deprecated.ts",
"require": "./src/exports/types-deprecated.ts",
"types": "./src/exports/types-deprecated.ts"
},
"./migration-utils": {
"import": "./src/exports/migration-utils.ts",
"require": "./src/exports/migration-utils.ts",
"types": "./src/exports/migration-utils.ts"
},
"./drizzle": {
"import": "./src/drizzle-proxy/index.ts",
"types": "./src/drizzle-proxy/index.ts",
"default": "./src/drizzle-proxy/index.ts"
},
"./drizzle/sqlite-core": {
"import": "./src/drizzle-proxy/sqlite-core.ts",
"types": "./src/drizzle-proxy/sqlite-core.ts",
"default": "./src/drizzle-proxy/sqlite-core.ts"
},
"./drizzle/d1": {
"import": "./src/drizzle-proxy/d1.ts",
"types": "./src/drizzle-proxy/d1.ts",
"default": "./src/drizzle-proxy/d1.ts"
},
"./drizzle/relations": {
"import": "./src/drizzle-proxy/relations.ts",
"types": "./src/drizzle-proxy/relations.ts",
"default": "./src/drizzle-proxy/relations.ts"
}
},
"main": "./src/index.ts",
"types": "./src/index.ts",
"files": [
"dist",
"mock.js"
],
"scripts": {
"build": "pnpm build:swc && pnpm build:types",
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
"build:types": "tsc --emitDeclarationOnly --outDir dist",
"clean": "rimraf -g {dist,*.tsbuildinfo}",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "pnpm clean && pnpm turbo build",
"prepublishOnly": "pnpm clean && pnpm turbo build"
},
"dependencies": {
"@payloadcms/drizzle": "workspace:*",
"console-table-printer": "2.12.1",
"drizzle-kit": "0.31.4",
"drizzle-orm": "0.44.2",
"prompts": "2.4.2",
"to-snake-case": "1.0.0",
"uuid": "9.0.0"
},
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"@types/pg": "8.10.2",
"@types/to-snake-case": "1.0.0",
"@types/uuid": "10.0.0",
"payload": "workspace:*"
},
"peerDependencies": {
"payload": "workspace:*"
},
"publishConfig": {
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./types": {
"import": "./dist/exports/types-deprecated.js",
"require": "./dist/exports/types-deprecated.js",
"types": "./dist/exports/types-deprecated.d.ts"
},
"./migration-utils": {
"import": "./dist/exports/migration-utils.js",
"require": "./dist/exports/migration-utils.js",
"types": "./dist/exports/migration-utils.d.ts"
},
"./drizzle": {
"import": "./dist/drizzle-proxy/index.js",
"types": "./dist/drizzle-proxy/index.d.ts",
"default": "./dist/drizzle-proxy/index.js"
},
"./drizzle/sqlite-core": {
"import": "./dist/drizzle-proxy/sqlite-core.js",
"types": "./dist/drizzle-proxy/sqlite-core.d.ts",
"default": "./dist/drizzle-proxy/sqlite-core.js"
},
"./drizzle/d1": {
"import": "./dist/drizzle-proxy/d1.js",
"types": "./dist/drizzle-proxy/d1.d.ts",
"default": "./dist/drizzle-proxy/d1.js"
},
"./drizzle/relations": {
"import": "./dist/drizzle-proxy/relations.js",
"types": "./dist/drizzle-proxy/relations.d.ts",
"default": "./dist/drizzle-proxy/relations.js"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts"
}
}
Loading
Loading