Skip to content

Commit bfd4e94

Browse files
Oxyjunpedrosousa
andauthored
Apply suggestions from code review
Co-authored-by: Pedro Sousa <[email protected]>
1 parent 8d30e02 commit bfd4e94

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/content/docs/durable-objects/api/sql-storage.mdx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ The `SqlStorage` interface encapsulates methods that modify the SQLite database
1212

1313
For example, using `sql.exec()`, a user can create a table, then insert rows into the table.
1414

15-
```js
15+
```ts
1616
import { DurableObject } from "cloudflare:workers";
1717

1818
export class MyDurableObject extends DurableObject {
19-
sql: SqlStorage
19+
sql: SqlStorage;
2020
constructor(ctx: DurableObjectState, env: Env) {
2121
super(ctx, env);
2222
this.sql = ctx.storage.sql;
@@ -59,7 +59,7 @@ A cursor (`SqlStorageCursor`) to iterate over query row results as objects. `Sql
5959
`SqlStorageCursor` supports the following methods:
6060

6161
* `next()`
62-
* Returns an object representing the next value of the cursor. The returned object has `done` and `value` properties adhering to the JavaScript [Iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol). `done` is set to `false` when a next value is present, and `value` is set to the next row object in the query result. `done` is set to `true` when the entire cursor is consumed, and no `value` is set.
62+
* Returns an object representing the next value of the cursor. The returned object has `done` and `value` properties adhering to the JavaScript [Iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol). `done` is set to `false` when a next value is present, and `value` is set to the next row object in the query result. `done` is set to `true` when the entire cursor is consumed, and no `value` is set.
6363
* `toArray()`
6464
* Iterates through remaining cursor value(s) and returns an array of returned row objects.
6565
* `one()`
@@ -70,17 +70,18 @@ A cursor (`SqlStorageCursor`) to iterate over query row results as objects. `Sql
7070
* Returned cursor and `raw()` iterator iterate over the same query results and can be combined. For example:
7171

7272
```ts
73-
let cursor = this.sql.exec("SELECT * FROM artist ORDER BY artistname ASC;");
74-
let rawResult = cursor.raw().next();
73+
let cursor = this.sql.exec("SELECT * FROM artist ORDER BY artistname ASC;");
74+
let rawResult = cursor.raw().next();
7575

76-
if (!rawResult.done) {
77-
console.log(rawResult.value); // prints [ 123, 'Alice' ]
78-
} else {
79-
// query returned zero results
80-
}
76+
if (!rawResult.done) {
77+
console.log(rawResult.value); // prints [ 123, 'Alice' ]
78+
} else {
79+
// query returned zero results
80+
}
8181

82-
console.log(cursor.toArray()); // prints [{ artistid: 456, artistname: 'Bob' },{ artistid: 789, artistname: 'Charlie' }]
82+
console.log(cursor.toArray()); // prints [{ artistid: 456, artistname: 'Bob' },{ artistid: 789, artistname: 'Charlie' }]
8383
```
84+
8485
`SqlStorageCursor` had the following properties:
8586

8687
* `columnNames`: <Type text='string[]' />
@@ -101,10 +102,11 @@ Note that `sql.exec()` cannot execute transaction-related statements like `BEGIN
101102
`databaseSize`: <Type text ='number' />
102103

103104
#### Returns
105+
104106
The current SQLite database size in bytes.
105107

106108
```ts
107-
let size = ctx.storage.sql.databaseSize;
109+
let size = ctx.storage.sql.databaseSize;
108110
```
109111

110112
## Point in time recovery
@@ -117,13 +119,13 @@ The PITR API represents points in times using "bookmarks". A bookmark is a mostl
117119

118120
<code>ctx.storage.getCurrentBookmark()</code>: <Type text='Promise<string>' />
119121

120-
* Returns a bookmark representing the current point in time in the object's history.
122+
* Returns a bookmark representing the current point in time in the object's history.
121123

122124
### `getBookmarkForTime`
123125

124-
<code>ctx.storage.getBookmarkForTime(timestamp: <Type text='number'/> | <Type text='Date'/>)</code>: <Type text='Promise<string>' />
126+
<code>ctx.storage.getBookmarkForTime(timestamp: <Type text='number | Date'/>)</code>: <Type text='Promise<string>' />
125127

126-
* Returns a bookmark representing approximately the given point in time, which must be within the last 30 days. If the timestamp is represented as a number, it is converted to a date as if using `new Date(timestamp)`.
128+
* Returns a bookmark representing approximately the given point in time, which must be within the last 30 days. If the timestamp is represented as a number, it is converted to a date as if using `new Date(timestamp)`.
127129

128130
### `onNextSessionRestoreBookmark`
129131

@@ -135,8 +137,8 @@ The PITR API represents points in times using "bookmarks". A bookmark is a mostl
135137

136138

137139
```ts
138-
let now = new Date();
139-
// restore to 2 days ago
140-
let bookmark = ctx.storage.getBookmarkForTime(now - 2);
141-
ctx.storage.onNextSessionRestoreBookmark(bookmark);
140+
let now = new Date();
141+
// restore to 2 days ago
142+
let bookmark = ctx.storage.getBookmarkForTime(now - 2);
143+
ctx.storage.onNextSessionRestoreBookmark(bookmark);
142144
```

src/content/docs/durable-objects/api/storage-api.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Counter {
4343

4444
:::note[SQLite in Durable Objects Beta]
4545

46-
The new beta version of Durable Objects is available where each Durable Object has a private, embedded SQLite database. When deploying a new Durable Object class, users can [opt-in to a SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend) in order to access new [SQL API](/durable-objects/api/sql-storage/#exec). Otherwise, a Durable Object class has a key-value storage backend.
46+
The new beta version of Durable Objects is available where each Durable Object has a private, embedded SQLite database. When deploying a new Durable Object class, users can [opt-in to a SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend) to access the new [SQL API](/durable-objects/api/sql-storage/#exec). Otherwise, a Durable Object class has a key-value storage backend.
4747

4848
:::
4949

@@ -209,7 +209,7 @@ The `put()` method returns a `Promise`, but most applications can discard this p
209209

210210
### `sync`
211211

212-
* `sync()` : <Type text='Promise' />
212+
* `sync()`: <Type text='Promise' />
213213

214214
* Synchronizes any pending writes to disk.
215215

@@ -247,7 +247,7 @@ The `put()` method returns a `Promise`, but most applications can discard this p
247247

248248
### `sql`
249249

250-
`sql` is a readonly property of type `DurableObjectStorage` encapsulating the [SQL API](/durable-objects/api/sql-storage).
250+
`sql` is a readonly property of type `DurableObjectStorage` encapsulating the [SQL API](/durable-objects/api/sql-storage/).
251251

252252
## Related resources
253253

src/content/docs/durable-objects/api/websockets.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ To learn more about WebSocket Hibernation, refer to [Build a WebSocket server wi
4343

4444
### `acceptWebSocket`
4545

46-
- <code>acceptWebSocket(ws <Type text="WebSocket" />, tags{" "}<Type text="Array<string>" /> <MetaInfo text="optional" />)</code>: <Type text="void" />
46+
- <code>acceptWebSocket(ws <Type text="WebSocket" />, tags <Type text="Array<string>" /> <MetaInfo text="optional" />)</code>: <Type text="void" />
4747

4848
- Adds a WebSocket to the set attached to this Durable Object. `ws.accept()` must not have been called separately. Once called, any incoming messages will be delivered by calling the Durable Object's `webSocketMessage()` handler, and `webSocketClose()` will be invoked upon disconnect.
4949

0 commit comments

Comments
 (0)