@h-ai/reldb 0.1.0-alpha.32 → 0.1.0-alpha.34
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.
- package/README.md +4 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -303,6 +303,10 @@ class UserRepository extends BaseReldbCrudRepository<UserRow> {
|
|
|
303
303
|
|
|
304
304
|
/** 自定义方法中使用 this.sql(tx) 自动路由到事务 */
|
|
305
305
|
async insertRaw(data: { name: string, email: string }, tx?: DmlWithTxOperations) {
|
|
306
|
+
// 自定义原始写操作应先确保表已就绪(避免刚建库/建表较慢时的竞态)
|
|
307
|
+
const ready = await this.ensureReady()
|
|
308
|
+
if (!ready.success)
|
|
309
|
+
return ready
|
|
306
310
|
const now = Date.now()
|
|
307
311
|
return this.sql(tx).execute(
|
|
308
312
|
'INSERT INTO users (name, email, created_at, updated_at) VALUES (?, ?, ?, ?)',
|
package/dist/index.d.ts
CHANGED
|
@@ -1310,11 +1310,15 @@ declare abstract class BaseReldbCrudRepository<TItem> implements ReldbCrudReposi
|
|
|
1310
1310
|
*/
|
|
1311
1311
|
private buildUpdatePayload;
|
|
1312
1312
|
/**
|
|
1313
|
-
*
|
|
1313
|
+
* 等待初始化完成(自动建表等)
|
|
1314
|
+
*
|
|
1315
|
+
* 内置 CRUD 方法均已在执行前调用;自定义方法若通过 `this.sql()` 直接执行原始
|
|
1316
|
+
* SQL(尤其是写操作或在事务中),应先 `await this.ensureReady()` 以避免表尚未
|
|
1317
|
+
* 建好时(例如刚 dropTable 后、或后端建表较慢时)产生「表不存在」的竞态失败。
|
|
1314
1318
|
*
|
|
1315
1319
|
* @returns 初始化结果
|
|
1316
1320
|
*/
|
|
1317
|
-
|
|
1321
|
+
protected ensureReady(): Promise<HaiResult<void>>;
|
|
1318
1322
|
/**
|
|
1319
1323
|
* 创建单条记录
|
|
1320
1324
|
*
|
package/dist/index.js
CHANGED
|
@@ -490,7 +490,11 @@ var BaseReldbCrudRepository = class {
|
|
|
490
490
|
return payload;
|
|
491
491
|
}
|
|
492
492
|
/**
|
|
493
|
-
*
|
|
493
|
+
* 等待初始化完成(自动建表等)
|
|
494
|
+
*
|
|
495
|
+
* 内置 CRUD 方法均已在执行前调用;自定义方法若通过 `this.sql()` 直接执行原始
|
|
496
|
+
* SQL(尤其是写操作或在事务中),应先 `await this.ensureReady()` 以避免表尚未
|
|
497
|
+
* 建好时(例如刚 dropTable 后、或后端建表较慢时)产生「表不存在」的竞态失败。
|
|
494
498
|
*
|
|
495
499
|
* @returns 初始化结果
|
|
496
500
|
*/
|