@stonyx/orm 0.3.2-beta.327 → 0.3.2-beta.329
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 +2 -0
- package/config/environment.js +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/main.d.ts +1 -0
- package/dist/manage-record.d.ts +4 -0
- package/dist/manage-record.js +72 -42
- package/dist/mysql/connection.d.ts +2 -0
- package/dist/mysql/mysql-db.d.ts +32 -10
- package/dist/mysql/mysql-db.js +218 -58
- package/dist/mysql/query-builder.d.ts +1 -0
- package/dist/mysql/query-builder.js +17 -0
- package/dist/postgres/postgres-db.d.ts +1 -0
- package/dist/postgres/postgres-db.js +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/main.ts +1 -0
- package/src/manage-record.ts +89 -42
- package/src/mysql/connection.ts +2 -0
- package/src/mysql/mysql-db.ts +242 -56
- package/src/mysql/query-builder.ts +21 -0
- package/src/postgres/postgres-db.ts +1 -0
|
@@ -27,6 +27,27 @@ export function buildInsert(table: string, data: Record<string, unknown>): Query
|
|
|
27
27
|
return { sql, values };
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
export function buildInsertMany(table: string, rows: Record<string, unknown>[]): QueryResult {
|
|
31
|
+
validateIdentifier(table, 'table name');
|
|
32
|
+
|
|
33
|
+
const columns = [...new Set(rows.flatMap(row => Object.keys(row)))];
|
|
34
|
+
columns.forEach(column => validateIdentifier(column, 'column name'));
|
|
35
|
+
|
|
36
|
+
const values: unknown[] = [];
|
|
37
|
+
const tuples = rows.map(row => {
|
|
38
|
+
const cells = columns.map(column => {
|
|
39
|
+
if (!Object.hasOwn(row, column)) return 'DEFAULT';
|
|
40
|
+
values.push(row[column]);
|
|
41
|
+
return '?';
|
|
42
|
+
});
|
|
43
|
+
return `(${cells.join(', ')})`;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const sql = `INSERT INTO \`${table}\` (${columns.map(column => `\`${column}\``).join(', ')}) VALUES ${tuples.join(', ')}`;
|
|
47
|
+
|
|
48
|
+
return { sql, values };
|
|
49
|
+
}
|
|
50
|
+
|
|
30
51
|
export function buildUpdate(table: string, id: unknown, data: Record<string, unknown>): QueryResult {
|
|
31
52
|
validateIdentifier(table, 'table name');
|
|
32
53
|
|
|
@@ -134,6 +134,7 @@ export default class PostgresDB {
|
|
|
134
134
|
pool!: Pool | null;
|
|
135
135
|
pgConfig!: Record<string, unknown>;
|
|
136
136
|
|
|
137
|
+
readonly persistResolvesAfterWrite = true;
|
|
137
138
|
private _queuedWrites: QueuedWrite[] = [];
|
|
138
139
|
private _inFlightWrites = new Set<QueuedWrite>();
|
|
139
140
|
private _drainingWrites: Promise<void> | null = null;
|