@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.
@@ -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;