Skip to content
Open
Changes from all commits
Commits
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
55 changes: 28 additions & 27 deletions src/content/docs/connect-cloudflare-do.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,38 @@ drizzle-orm

#### Step 2 - Initialize the driver and make a query

You would need to have a `wrangler.toml` file for Durable Objects database and will look something like this:
```toml {16-18,21-24}
#:schema node_modules/wrangler/config-schema.json
name = "sqlite-durable-objects"
main = "src/index.ts"
compatibility_date = "2024-11-12"
compatibility_flags = [ "nodejs_compat" ]

# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
[[durable_objects.bindings]]
name = "MY_DURABLE_OBJECT"
class_name = "MyDurableObject"

# Durable Object migrations.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
[[migrations]]
tag = "v1"
new_sqlite_classes = ["MyDurableObject"]

# We need rules so we can import migrations in the next steps
[[rules]]
type = "Text"
globs = ["**/*.sql"]
fallthrough = true
You would need to have a `wrangler.jsonc` file for Durable Objects database and will look something like this:
```jsonc
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "sqlite-durable-objects",
"main": "./src/index.ts",
"compatibility_date": "2024-11-12",
"compatibility_flags": ["nodejs_compat"],
"durable_objects": {
// Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
// Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
// Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
"bindings": [
{
"name": "MY_DURABLE_OBJECT",
"class_name": "MyDurableObject"
}
]
},
// Durable Object migrations.
// Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
"migrations": [
{
"tag": "v1",
"new_sqlite_classes": ["MyDurableObject"]
}
]
}
```

Make your first Durable Objects SQLite query:
```typescript copy
/// <reference types="@cloudflare/workers-types" />
import { drizzle, DrizzleSqliteDODatabase } from 'drizzle-orm/durable-sqlite';
import { DurableObject } from 'cloudflare:workers'
import { migrate } from 'drizzle-orm/durable-sqlite/migrator';
Expand Down