(
schemaName: string,
tableName: string,
ops: DatabaseTableOperation[],
validateSchema?: DatabaseTableSchema
)
| 43 | } |
| 44 | |
| 45 | async updateTableData( |
| 46 | schemaName: string, |
| 47 | tableName: string, |
| 48 | ops: DatabaseTableOperation[], |
| 49 | validateSchema?: DatabaseTableSchema |
| 50 | ): Promise<DatabaseTableOperationReslt[]> { |
| 51 | if (validateSchema) { |
| 52 | this.validateUpdateOperation(ops, validateSchema); |
| 53 | } |
| 54 | |
| 55 | const sqls = ops.map((op) => { |
| 56 | if (op.operation === "INSERT") |
| 57 | return insertInto( |
| 58 | this, |
| 59 | schemaName, |
| 60 | tableName, |
| 61 | op.values, |
| 62 | this.getFlags().supportInsertReturning, |
| 63 | this.getFlags().supportRowId |
| 64 | ); |
| 65 | |
| 66 | if (op.operation === "DELETE") |
| 67 | return deleteFrom(this, schemaName, tableName, op.where); |
| 68 | |
| 69 | return updateTable( |
| 70 | this, |
| 71 | schemaName, |
| 72 | tableName, |
| 73 | op.values, |
| 74 | op.where, |
| 75 | this.getFlags().supportInsertReturning, |
| 76 | this.getFlags().supportRowId |
| 77 | ); |
| 78 | }); |
| 79 | |
| 80 | const result = await this.transaction(sqls); |
| 81 | |
| 82 | const tmp: DatabaseTableOperationReslt[] = []; |
| 83 | |
| 84 | for (let i = 0; i < result.length; i++) { |
| 85 | const r = result[i]; |
| 86 | const op = ops[i]; |
| 87 | |
| 88 | if (!r || !op) { |
| 89 | tmp.push({}); |
| 90 | continue; |
| 91 | } |
| 92 | |
| 93 | if (op.operation === "UPDATE") { |
| 94 | if (r.rows.length === 1) |
| 95 | // This is when database support RETURNING |
| 96 | tmp.push({ |
| 97 | record: r.rows[0], |
| 98 | }); |
| 99 | else { |
| 100 | const selectResult = await this.findFirst( |
| 101 | schemaName, |
| 102 | tableName, |
nothing calls this directly
no test coverage detected