You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`execSync(sql)`|`void`| Execute a DDL statement |
113
114
|`querySync(sql, params?)`|`Object[]`| Query rows as objects |
@@ -189,6 +190,24 @@ Controls the durability vs. performance trade-off:
189
190
|`compression`|| Set both `wal_compression` and `snapshot_compression`|
190
191
|`compression_threshold`|`64`| Minimum bytes before compressing an entry |
191
192
193
+
#### Cloning
194
+
195
+
`clone()` creates a new `Database` handle that shares the same underlying engine (data, indexes, transactions) but has its own executor and error state. Useful for concurrent access patterns such as worker threads.
196
+
197
+
```js
198
+
constdb=awaitDatabase.open('./mydata');
199
+
constdb2=db.clone();
200
+
201
+
// Both see the same data
202
+
awaitdb.execute('INSERT INTO users VALUES ($1, $2)', [1, 'Alice']);
203
+
constrow=db2.queryOneSync('SELECT * FROM users WHERE id = $1', [1]);
204
+
// { id: 1, name: 'Alice' }
205
+
206
+
// Each clone must be closed independently
207
+
awaitdb2.close();
208
+
awaitdb.close();
209
+
```
210
+
192
211
#### Raw Query Format
193
212
194
213
`queryRaw` / `queryRawSync` return `{ columns: string[], rows: any[][] }` instead of an array of objects. Faster when you don't need named keys.
0 commit comments