@molecule/api-database 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +299 -299
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-10-15T12:34:32.789Z
6
+ Generated: 2026-10-16T00:26:28.689Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-database
@@ -61,73 +61,183 @@ npm install @molecule/api-database @molecule/api-bond @molecule/api-i18n
61
61
 
62
62
  ### Interfaces
63
63
 
64
- #### `DatabaseConfig`
64
+ #### `WhereCondition`
65
65
 
66
- Database connection options (host, port, credentials, pool size, timeouts, SSL).
66
+ Filter condition for queries.
67
67
 
68
68
  ```typescript
69
- interface DatabaseConfig {
69
+ interface WhereCondition {
70
+ field: string
71
+ operator:
72
+ | '='
73
+ | '!='
74
+ | '>'
75
+ | '<'
76
+ | '>='
77
+ | '<='
78
+ | 'in'
79
+ | 'not_in'
80
+ /**
81
+ * Case-insensitive SQL pattern match. `value` is used AS-IS as the raw
82
+ * LIKE pattern: `%` matches any run of characters, `_` matches any
83
+ * single character, and the CALLER is responsible for escaping any
84
+ * literal `%` / `_` / `\` they don't want treated as wildcards. All
85
+ * three first-party bonds (postgresql, mysql, sqlite) implement `like`
86
+ * case-INSENSITIVELY — postgres via `ILIKE`, mysql/sqlite via
87
+ * `LOWER()` on both sides — specifically so this operator has
88
+ * IDENTICAL results across every bond regardless of column collation
89
+ * or `PRAGMA case_sensitive_like`. Prior to this contract the postgres
90
+ * bond escaped the value (making `like` an exact-match operator there
91
+ * only) while sqlite/mysql passed it through raw — the same `{
92
+ * operator: 'like', value: `%${search}%` }` filter silently matched
93
+ * nothing on postgres and worked everywhere else. For human-typed
94
+ * search input where the value should be a literal substring (not a
95
+ * pattern the caller controls), use `ilike` instead — it escapes
96
+ * wildcards and wraps `%…%` for you, so it is injection-safe for
97
+ * arbitrary user text.
98
+ */
99
+ | 'like'
100
+ /**
101
+ * Case-insensitive substring match. The value is treated as a
102
+ * literal substring (LIKE wildcards in the value are escaped) and
103
+ * the bond wraps it with `%…%` to perform a contains-style match.
104
+ * Use this for human-typed search input where case shouldn't matter.
105
+ */
106
+ | 'ilike'
107
+ | 'is_null'
108
+ | 'is_not_null'
109
+ value?: unknown
110
+ }
111
+ ```
112
+
113
+ #### `OrderBy`
114
+
115
+ Column sort order (field name and ascending/descending direction).
116
+
117
+ ```typescript
118
+ interface OrderBy {
119
+ field: string
120
+ direction: 'asc' | 'desc'
121
+ }
122
+ ```
123
+
124
+ #### `FindManyOptions`
125
+
126
+ Options for findMany queries.
127
+
128
+ ```typescript
129
+ interface FindManyOptions {
130
+ where?: WhereCondition[]
131
+ orderBy?: OrderBy[]
132
+ limit?: number
133
+ offset?: number
134
+ select?: string[]
135
+ }
136
+ ```
137
+
138
+ #### `MutationResult`
139
+
140
+ Result of a mutation operation.
141
+
142
+ ```typescript
143
+ interface MutationResult<T = Record<string, unknown>> {
144
+ /** The affected/returned row, if any. */
145
+ data: T | null
146
+ /** Number of rows affected. */
147
+ affected: number
148
+ }
149
+ ```
150
+
151
+ #### `DataStore`
152
+
153
+ Abstract data store interface.
154
+
155
+ Provides database-agnostic CRUD methods. Each database bond
156
+ implements these using its native query language.
157
+
158
+ ```typescript
159
+ interface DataStore {
70
160
  /**
71
- * Database host.
161
+ * Find a single record by its primary key.
72
162
  */
73
- host?: string
163
+ findById<T = Record<string, unknown>>(table: string, id: string | number): Promise<T | null>
74
164
 
75
165
  /**
76
- * Database port.
166
+ * Find a single record matching conditions.
77
167
  */
78
- port?: number
168
+ findOne<T = Record<string, unknown>>(table: string, where: WhereCondition[]): Promise<T | null>
79
169
 
80
170
  /**
81
- * Database name.
171
+ * Find many records with filtering, sorting, and pagination.
82
172
  */
83
- database?: string
173
+ findMany<T = Record<string, unknown>>(table: string, options?: FindManyOptions): Promise<T[]>
84
174
 
85
175
  /**
86
- * Database user.
176
+ * Count records matching conditions.
87
177
  */
88
- user?: string
178
+ count(table: string, where?: WhereCondition[]): Promise<number>
89
179
 
90
180
  /**
91
- * Database password.
181
+ * Insert a new record. Returns the inserted row.
92
182
  */
93
- password?: string
183
+ create<T = Record<string, unknown>>(
184
+ table: string,
185
+ data: Record<string, unknown>,
186
+ ): Promise<MutationResult<T>>
94
187
 
95
188
  /**
96
- * Connection string (alternative to individual fields).
189
+ * Update a record by primary key. Returns the updated row.
97
190
  */
98
- connectionString?: string
191
+ updateById<T = Record<string, unknown>>(
192
+ table: string,
193
+ id: string | number,
194
+ data: Record<string, unknown>,
195
+ ): Promise<MutationResult<T>>
99
196
 
100
197
  /**
101
- * Maximum number of connections in the pool.
198
+ * Update records matching conditions.
102
199
  */
103
- max?: number
200
+ updateMany(
201
+ table: string,
202
+ where: WhereCondition[],
203
+ data: Record<string, unknown>,
204
+ ): Promise<MutationResult>
104
205
 
105
206
  /**
106
- * Minimum number of connections in the pool.
207
+ * Delete a record by primary key.
107
208
  */
108
- min?: number
209
+ deleteById(table: string, id: string | number): Promise<MutationResult>
109
210
 
110
211
  /**
111
- * Connection timeout in milliseconds.
212
+ * Delete records matching conditions.
112
213
  */
113
- connectionTimeoutMillis?: number
214
+ deleteMany(table: string, where: WhereCondition[]): Promise<MutationResult>
215
+ }
216
+ ```
217
+
218
+ #### `QueryResult`
219
+
220
+ Query result with rows and metadata.
114
221
 
222
+ ```typescript
223
+ interface QueryResult<T = Record<string, unknown>> {
115
224
  /**
116
- * Idle timeout in milliseconds.
225
+ * Array of rows returned by the query.
117
226
  */
118
- idleTimeoutMillis?: number
227
+ rows: T[]
119
228
 
120
229
  /**
121
- * Enable SSL.
230
+ * Number of rows affected (for INSERT, UPDATE, DELETE).
122
231
  */
123
- ssl?:
124
- | boolean
125
- | {
126
- rejectUnauthorized?: boolean
127
- ca?: string
128
- key?: string
129
- cert?: string
130
- }
232
+ rowCount: number | null
233
+
234
+ /**
235
+ * Column metadata (optional, provider-dependent).
236
+ */
237
+ fields?: Array<{
238
+ name: string
239
+ dataTypeID?: number
240
+ }>
131
241
  }
132
242
  ```
133
243
 
@@ -152,6 +262,24 @@ interface DatabaseConnection {
152
262
  }
153
263
  ```
154
264
 
265
+ #### `DatabaseTransaction`
266
+
267
+ Database transaction with commit and rollback (extends DatabaseConnection).
268
+
269
+ ```typescript
270
+ interface DatabaseTransaction extends DatabaseConnection {
271
+ /**
272
+ * Commits the transaction.
273
+ */
274
+ commit(): Promise<void>
275
+
276
+ /**
277
+ * Rolls back the transaction.
278
+ */
279
+ rollback(): Promise<void>
280
+ }
281
+ ```
282
+
155
283
  #### `DatabasePool`
156
284
 
157
285
  Database pool interface.
@@ -212,205 +340,121 @@ interface DatabaseProvider {
212
340
  }
213
341
  ```
214
342
 
215
- #### `DatabaseTransaction`
343
+ #### `DatabaseConfig`
216
344
 
217
- Database transaction with commit and rollback (extends DatabaseConnection).
345
+ Database connection options (host, port, credentials, pool size, timeouts, SSL).
218
346
 
219
347
  ```typescript
220
- interface DatabaseTransaction extends DatabaseConnection {
348
+ interface DatabaseConfig {
221
349
  /**
222
- * Commits the transaction.
350
+ * Database host.
223
351
  */
224
- commit(): Promise<void>
352
+ host?: string
225
353
 
226
354
  /**
227
- * Rolls back the transaction.
355
+ * Database port.
228
356
  */
229
- rollback(): Promise<void>
230
- }
231
- ```
232
-
233
- #### `DataStore`
234
-
235
- Abstract data store interface.
236
-
237
- Provides database-agnostic CRUD methods. Each database bond
238
- implements these using its native query language.
357
+ port?: number
239
358
 
240
- ```typescript
241
- interface DataStore {
242
359
  /**
243
- * Find a single record by its primary key.
360
+ * Database name.
244
361
  */
245
- findById<T = Record<string, unknown>>(table: string, id: string | number): Promise<T | null>
362
+ database?: string
246
363
 
247
364
  /**
248
- * Find a single record matching conditions.
365
+ * Database user.
249
366
  */
250
- findOne<T = Record<string, unknown>>(table: string, where: WhereCondition[]): Promise<T | null>
367
+ user?: string
251
368
 
252
369
  /**
253
- * Find many records with filtering, sorting, and pagination.
370
+ * Database password.
254
371
  */
255
- findMany<T = Record<string, unknown>>(table: string, options?: FindManyOptions): Promise<T[]>
372
+ password?: string
256
373
 
257
374
  /**
258
- * Count records matching conditions.
375
+ * Connection string (alternative to individual fields).
259
376
  */
260
- count(table: string, where?: WhereCondition[]): Promise<number>
377
+ connectionString?: string
261
378
 
262
379
  /**
263
- * Insert a new record. Returns the inserted row.
380
+ * Maximum number of connections in the pool.
264
381
  */
265
- create<T = Record<string, unknown>>(
266
- table: string,
267
- data: Record<string, unknown>,
268
- ): Promise<MutationResult<T>>
382
+ max?: number
269
383
 
270
384
  /**
271
- * Update a record by primary key. Returns the updated row.
385
+ * Minimum number of connections in the pool.
272
386
  */
273
- updateById<T = Record<string, unknown>>(
274
- table: string,
275
- id: string | number,
276
- data: Record<string, unknown>,
277
- ): Promise<MutationResult<T>>
387
+ min?: number
278
388
 
279
389
  /**
280
- * Update records matching conditions.
390
+ * Connection timeout in milliseconds.
281
391
  */
282
- updateMany(
283
- table: string,
284
- where: WhereCondition[],
285
- data: Record<string, unknown>,
286
- ): Promise<MutationResult>
392
+ connectionTimeoutMillis?: number
287
393
 
288
394
  /**
289
- * Delete a record by primary key.
395
+ * Idle timeout in milliseconds.
290
396
  */
291
- deleteById(table: string, id: string | number): Promise<MutationResult>
397
+ idleTimeoutMillis?: number
292
398
 
293
399
  /**
294
- * Delete records matching conditions.
400
+ * Enable SSL.
295
401
  */
296
- deleteMany(table: string, where: WhereCondition[]): Promise<MutationResult>
402
+ ssl?:
403
+ | boolean
404
+ | {
405
+ rejectUnauthorized?: boolean
406
+ ca?: string
407
+ key?: string
408
+ cert?: string
409
+ }
297
410
  }
298
411
  ```
299
412
 
300
- #### `FindManyOptions`
301
-
302
- Options for findMany queries.
303
-
304
- ```typescript
305
- interface FindManyOptions {
306
- where?: WhereCondition[]
307
- orderBy?: OrderBy[]
308
- limit?: number
309
- offset?: number
310
- select?: string[]
311
- }
312
- ```
413
+ ### Functions
313
414
 
314
- #### `MutationResult`
415
+ #### `setPool(pool)`
315
416
 
316
- Result of a mutation operation.
417
+ Registers a database connection pool as the active singleton. Called by
418
+ bond packages during application startup.
317
419
 
318
420
  ```typescript
319
- interface MutationResult<T = Record<string, unknown>> {
320
- /** The affected/returned row, if any. */
321
- data: T | null
322
- /** Number of rows affected. */
323
- affected: number
324
- }
421
+ function setPool(pool: DatabasePool): void
325
422
  ```
326
423
 
327
- #### `OrderBy`
424
+ - `pool` — The database pool implementation to bond.
328
425
 
329
- Column sort order (field name and ascending/descending direction).
426
+ #### `getPool()`
427
+
428
+ Retrieves the bonded database pool, throwing if none is configured.
330
429
 
331
430
  ```typescript
332
- interface OrderBy {
333
- field: string
334
- direction: 'asc' | 'desc'
335
- }
431
+ function getPool(): DatabasePool
336
432
  ```
337
433
 
338
- #### `QueryResult`
339
-
340
- Query result with rows and metadata.
434
+ **Returns:** The bonded database pool.
341
435
 
342
- ```typescript
343
- interface QueryResult<T = Record<string, unknown>> {
344
- /**
345
- * Array of rows returned by the query.
346
- */
347
- rows: T[]
436
+ #### `hasPool()`
348
437
 
349
- /**
350
- * Number of rows affected (for INSERT, UPDATE, DELETE).
351
- */
352
- rowCount: number | null
438
+ Checks whether a database pool is currently bonded.
353
439
 
354
- /**
355
- * Column metadata (optional, provider-dependent).
356
- */
357
- fields?: Array<{
358
- name: string
359
- dataTypeID?: number
360
- }>
361
- }
440
+ ```typescript
441
+ function hasPool(): boolean
362
442
  ```
363
443
 
364
- #### `WhereCondition`
444
+ **Returns:** `true` if a database pool is bonded.
365
445
 
366
- Filter condition for queries.
446
+ #### `query(text, values)`
447
+
448
+ Executes a parameterized SQL query using the bonded pool.
367
449
 
368
450
  ```typescript
369
- interface WhereCondition {
370
- field: string
371
- operator:
372
- | '='
373
- | '!='
374
- | '>'
375
- | '<'
376
- | '>='
377
- | '<='
378
- | 'in'
379
- | 'not_in'
380
- /**
381
- * Case-insensitive SQL pattern match. `value` is used AS-IS as the raw
382
- * LIKE pattern: `%` matches any run of characters, `_` matches any
383
- * single character, and the CALLER is responsible for escaping any
384
- * literal `%` / `_` / `\` they don't want treated as wildcards. All
385
- * three first-party bonds (postgresql, mysql, sqlite) implement `like`
386
- * case-INSENSITIVELY — postgres via `ILIKE`, mysql/sqlite via
387
- * `LOWER()` on both sides — specifically so this operator has
388
- * IDENTICAL results across every bond regardless of column collation
389
- * or `PRAGMA case_sensitive_like`. Prior to this contract the postgres
390
- * bond escaped the value (making `like` an exact-match operator there
391
- * only) while sqlite/mysql passed it through raw — the same `{
392
- * operator: 'like', value: `%${search}%` }` filter silently matched
393
- * nothing on postgres and worked everywhere else. For human-typed
394
- * search input where the value should be a literal substring (not a
395
- * pattern the caller controls), use `ilike` instead — it escapes
396
- * wildcards and wraps `%…%` for you, so it is injection-safe for
397
- * arbitrary user text.
398
- */
399
- | 'like'
400
- /**
401
- * Case-insensitive substring match. The value is treated as a
402
- * literal substring (LIKE wildcards in the value are escaped) and
403
- * the bond wraps it with `%…%` to perform a contains-style match.
404
- * Use this for human-typed search input where case shouldn't matter.
405
- */
406
- | 'ilike'
407
- | 'is_null'
408
- | 'is_not_null'
409
- value?: unknown
410
- }
451
+ function query(text: string, values?: unknown[]): Promise<QueryResult<T>>
411
452
  ```
412
453
 
413
- ### Functions
454
+ - `text` — SQL query text with placeholders (`$1`, `$2`, etc.).
455
+ - `values` — Parameter values corresponding to the placeholders.
456
+
457
+ **Returns:** The query result containing `rows`, `rowCount`, and optional `fields`.
414
458
 
415
459
  #### `connect()`
416
460
 
@@ -423,75 +467,46 @@ function connect(): Promise<DatabaseConnection>
423
467
 
424
468
  **Returns:** A database connection that must be released after use.
425
469
 
426
- #### `count(table, where)`
427
-
428
- Counts records matching the given filter conditions, or all records
429
- if no conditions are specified.
430
-
431
- ```typescript
432
- function count(table: string, where?: WhereCondition[]): Promise<number>
433
- ```
434
-
435
- - `table` — The database table name.
436
- - `where` — Optional filter conditions.
437
-
438
- **Returns:** The number of matching records.
439
-
440
- #### `create(table, data)`
470
+ #### `end()`
441
471
 
442
- Inserts a new record into the table. Returns the inserted row and
443
- the number of affected rows (always 1 on success).
472
+ Closes all connections in the bonded pool. Call during graceful shutdown.
444
473
 
445
474
  ```typescript
446
- function create(table: string, data: Record<string, unknown>): Promise<MutationResult<T>>
475
+ function end(): Promise<void>
447
476
  ```
448
477
 
449
- - `table` — The database table name.
450
- - `data` — The column values to insert as key-value pairs.
451
-
452
- **Returns:** A `MutationResult` with the inserted row and affected count.
478
+ **Returns:** A promise that resolves when all connections have been closed.
453
479
 
454
- #### `deleteById(table, id)`
480
+ #### `setStore(store)`
455
481
 
456
- Deletes a record identified by its primary key.
482
+ Registers a DataStore implementation as the active singleton. Called by
483
+ bond packages during application startup.
457
484
 
458
485
  ```typescript
459
- function deleteById(
460
- table: string,
461
- id: string | number,
462
- ): Promise<MutationResult<Record<string, unknown>>>
486
+ function setStore(store: DataStore): void
463
487
  ```
464
488
 
465
- - `table` — The database table name.
466
- - `id` — The primary key value of the record to delete.
467
-
468
- **Returns:** A `MutationResult` with the affected count (1 if deleted, 0 if not found).
489
+ - `store` — The DataStore implementation to bond.
469
490
 
470
- #### `deleteMany(table, where)`
491
+ #### `getStore()`
471
492
 
472
- Deletes all records matching the given filter conditions.
493
+ Retrieves the bonded DataStore, throwing if none is configured.
473
494
 
474
495
  ```typescript
475
- function deleteMany(
476
- table: string,
477
- where: WhereCondition[],
478
- ): Promise<MutationResult<Record<string, unknown>>>
496
+ function getStore(): DataStore
479
497
  ```
480
498
 
481
- - `table` — The database table name.
482
- - `where` — Filter conditions to select records to delete.
483
-
484
- **Returns:** A `MutationResult` with the number of deleted rows.
499
+ **Returns:** The bonded DataStore implementation.
485
500
 
486
- #### `end()`
501
+ #### `hasStore()`
487
502
 
488
- Closes all connections in the bonded pool. Call during graceful shutdown.
503
+ Checks whether a DataStore is currently bonded.
489
504
 
490
505
  ```typescript
491
- function end(): Promise<void>
506
+ function hasStore(): boolean
492
507
  ```
493
508
 
494
- **Returns:** A promise that resolves when all connections have been closed.
509
+ **Returns:** `true` if a DataStore is bonded.
495
510
 
496
511
  #### `findById(table, id)`
497
512
 
@@ -506,20 +521,6 @@ function findById(table: string, id: string | number): Promise<T | null>
506
521
 
507
522
  **Returns:** The matching record cast to `T`, or `null` if not found.
508
523
 
509
- #### `findMany(table, options)`
510
-
511
- Finds multiple records with optional filtering, sorting, pagination,
512
- and column selection.
513
-
514
- ```typescript
515
- function findMany(table: string, options?: FindManyOptions): Promise<T[]>
516
- ```
517
-
518
- - `table` — The database table name.
519
- - `options` — Query options including `where`, `orderBy`, `limit`, `offset`, and `select`.
520
-
521
- **Returns:** Array of matching records cast to `T`.
522
-
523
524
  #### `findOne(table, where)`
524
525
 
525
526
  Finds a single record matching the given filter conditions. Returns the
@@ -534,92 +535,47 @@ function findOne(table: string, where: WhereCondition[]): Promise<T | null>
534
535
 
535
536
  **Returns:** The matching record cast to `T`, or `null` if none found.
536
537
 
537
- #### `getActiveTransaction()`
538
-
539
- The transaction opened by the enclosing `withTransaction()` call, if any.
540
- Bond pools call this from `query()` and send the statement to the active
541
- transaction when it is one they opened.
542
-
543
- ```typescript
544
- function getActiveTransaction(): DatabaseTransaction | undefined
545
- ```
546
-
547
- **Returns:** The active transaction, or `undefined` outside `withTransaction()`.
548
-
549
- #### `getPool()`
550
-
551
- Retrieves the bonded database pool, throwing if none is configured.
552
-
553
- ```typescript
554
- function getPool(): DatabasePool
555
- ```
556
-
557
- **Returns:** The bonded database pool.
558
-
559
- #### `getStore()`
560
-
561
- Retrieves the bonded DataStore, throwing if none is configured.
562
-
563
- ```typescript
564
- function getStore(): DataStore
565
- ```
566
-
567
- **Returns:** The bonded DataStore implementation.
568
-
569
- #### `hasPool()`
538
+ #### `findMany(table, options)`
570
539
 
571
- Checks whether a database pool is currently bonded.
540
+ Finds multiple records with optional filtering, sorting, pagination,
541
+ and column selection.
572
542
 
573
543
  ```typescript
574
- function hasPool(): boolean
544
+ function findMany(table: string, options?: FindManyOptions): Promise<T[]>
575
545
  ```
576
546
 
577
- **Returns:** `true` if a database pool is bonded.
578
-
579
- #### `hasStore()`
580
-
581
- Checks whether a DataStore is currently bonded.
582
-
583
- ```typescript
584
- function hasStore(): boolean
585
- ```
547
+ - `table` — The database table name.
548
+ - `options` — Query options including `where`, `orderBy`, `limit`, `offset`, and `select`.
586
549
 
587
- **Returns:** `true` if a DataStore is bonded.
550
+ **Returns:** Array of matching records cast to `T`.
588
551
 
589
- #### `query(text, values)`
552
+ #### `count(table, where)`
590
553
 
591
- Executes a parameterized SQL query using the bonded pool.
554
+ Counts records matching the given filter conditions, or all records
555
+ if no conditions are specified.
592
556
 
593
557
  ```typescript
594
- function query(text: string, values?: unknown[]): Promise<QueryResult<T>>
558
+ function count(table: string, where?: WhereCondition[]): Promise<number>
595
559
  ```
596
560
 
597
- - `text` — SQL query text with placeholders (`$1`, `$2`, etc.).
598
- - `values` — Parameter values corresponding to the placeholders.
561
+ - `table` — The database table name.
562
+ - `where` — Optional filter conditions.
599
563
 
600
- **Returns:** The query result containing `rows`, `rowCount`, and optional `fields`.
564
+ **Returns:** The number of matching records.
601
565
 
602
- #### `setPool(pool)`
566
+ #### `create(table, data)`
603
567
 
604
- Registers a database connection pool as the active singleton. Called by
605
- bond packages during application startup.
568
+ Inserts a new record into the table. Returns the inserted row and
569
+ the number of affected rows (always 1 on success).
606
570
 
607
571
  ```typescript
608
- function setPool(pool: DatabasePool): void
572
+ function create(table: string, data: Record<string, unknown>): Promise<MutationResult<T>>
609
573
  ```
610
574
 
611
- - `pool` — The database pool implementation to bond.
612
-
613
- #### `setStore(store)`
614
-
615
- Registers a DataStore implementation as the active singleton. Called by
616
- bond packages during application startup.
617
-
618
- ```typescript
619
- function setStore(store: DataStore): void
620
- ```
575
+ - `table` — The database table name.
576
+ - `data` — The column values to insert as key-value pairs.
621
577
 
622
- - `store` — The DataStore implementation to bond.
578
+ **Returns:** A `MutationResult` with the inserted row and affected count.
623
579
 
624
580
  #### `updateById(table, id, data)`
625
581
 
@@ -658,6 +614,50 @@ function updateMany(
658
614
 
659
615
  **Returns:** A `MutationResult` with the affected count.
660
616
 
617
+ #### `deleteById(table, id)`
618
+
619
+ Deletes a record identified by its primary key.
620
+
621
+ ```typescript
622
+ function deleteById(
623
+ table: string,
624
+ id: string | number,
625
+ ): Promise<MutationResult<Record<string, unknown>>>
626
+ ```
627
+
628
+ - `table` — The database table name.
629
+ - `id` — The primary key value of the record to delete.
630
+
631
+ **Returns:** A `MutationResult` with the affected count (1 if deleted, 0 if not found).
632
+
633
+ #### `deleteMany(table, where)`
634
+
635
+ Deletes all records matching the given filter conditions.
636
+
637
+ ```typescript
638
+ function deleteMany(
639
+ table: string,
640
+ where: WhereCondition[],
641
+ ): Promise<MutationResult<Record<string, unknown>>>
642
+ ```
643
+
644
+ - `table` — The database table name.
645
+ - `where` — Filter conditions to select records to delete.
646
+
647
+ **Returns:** A `MutationResult` with the number of deleted rows.
648
+
649
+ #### `getActiveTransaction()`
650
+
651
+ The transaction opened by the enclosing `withTransaction()` call, if any.
652
+ Bond pools call this from `query()` and send the statement to the active
653
+ transaction when it is one they opened.
654
+
655
+ ```typescript
656
+ function getActiveTransaction(): DatabaseTransaction | undefined
657
+ ```
658
+
659
+ **Returns:** The active transaction, or `undefined` outside `withTransaction()`.
660
+
661
661
  #### `withTransaction(fn)`
662
662
 
663
663
  Runs `fn` inside one database transaction: commits when it resolves, rolls
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-database",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Database core interface for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",