Skip to content

Commit 31332ca

Browse files
authored
Update the C3 Durable Objects example to use SQlite (#8460)
1 parent 9adbd50 commit 31332ca

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

.changeset/chilled-moons-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": minor
3+
---
4+
5+
Update the C3 Durable Objects example to use SQLite

packages/create-cloudflare/templates/hello-world-durable-object/js/src/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@ export default {
5252
* @returns {Promise<Response>} The response to be sent back to the client
5353
*/
5454
async fetch(request, env, ctx) {
55-
// We will create a `DurableObjectId` using the pathname from the Worker request
56-
// This id refers to a unique instance of our 'MyDurableObject' class above
57-
let id = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname);
55+
// Create a `DurableObjectId` for an instance of the `MyDurableObject`
56+
// class named "foo". Requests from all Workers to the instance named
57+
// "foo" will go to a single globally unique Durable Object instance.
58+
const id = env.MY_DURABLE_OBJECT.idFromName("foo");
5859

59-
// This stub creates a communication channel with the Durable Object instance
60-
// The Durable Object constructor will be invoked upon the first call for a given id
61-
let stub = env.MY_DURABLE_OBJECT.get(id);
60+
// Create a stub to open a communication channel with the Durable
61+
// Object instance.
62+
const stub = env.MY_DURABLE_OBJECT.get(id);
6263

63-
// We call the `sayHello()` RPC method on the stub to invoke the method on the remote
64-
// Durable Object instance
65-
let greeting = await stub.sayHello("world");
64+
// Call the `sayHello()` RPC method on the stub to invoke the method on
65+
// the remote Durable Object instance
66+
const greeting = await stub.sayHello("world");
6667

6768
return new Response(greeting);
6869
},

packages/create-cloudflare/templates/hello-world-durable-object/js/wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"compatibility_date": "<TBD>",
55
"migrations": [
66
{
7-
"new_classes": [
7+
"new_sqlite_classes": [
88
"MyDurableObject"
99
],
1010
"tag": "v1"

packages/create-cloudflare/templates/hello-world-durable-object/ts/src/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ export default {
4848
* @returns The response to be sent back to the client
4949
*/
5050
async fetch(request, env, ctx): Promise<Response> {
51-
// We will create a `DurableObjectId` using the pathname from the Worker request
52-
// This id refers to a unique instance of our 'MyDurableObject' class above
53-
let id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname);
51+
// Create a `DurableObjectId` for an instance of the `MyDurableObject`
52+
// class named "foo". Requests from all Workers to the instance named
53+
// "foo" will go to a single globally unique Durable Object instance.
54+
const id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName("foo");
5455

55-
// This stub creates a communication channel with the Durable Object instance
56-
// The Durable Object constructor will be invoked upon the first call for a given id
57-
let stub = env.MY_DURABLE_OBJECT.get(id);
56+
// Create a stub to open a communication channel with the Durable
57+
// Object instance.
58+
const stub = env.MY_DURABLE_OBJECT.get(id);
5859

59-
// We call the `sayHello()` RPC method on the stub to invoke the method on the remote
60-
// Durable Object instance
61-
let greeting = await stub.sayHello("world");
60+
// Call the `sayHello()` RPC method on the stub to invoke the method on
61+
// the remote Durable Object instance
62+
const greeting = await stub.sayHello("world");
6263

6364
return new Response(greeting);
6465
},

packages/create-cloudflare/templates/hello-world-durable-object/ts/wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"compatibility_date": "<TBD>",
55
"migrations": [
66
{
7-
"new_classes": [
7+
"new_sqlite_classes": [
88
"MyDurableObject"
99
],
1010
"tag": "v1"

0 commit comments

Comments
 (0)