@inflector/optima-pg 1.0.3 → 1.0.5

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/dist/index.d.ts CHANGED
@@ -345,7 +345,7 @@ declare const vector: (dimension: number) => FluentStep<{
345
345
  }>;
346
346
  type AnyColumn = FluentStep<any, any, any>;
347
347
  declare const table: <T extends Record<string, AnyColumn>>(cols: T) => T;
348
- declare function getDefSQL(tableName: string, cols: Record<string, AnyColumn>): string;
348
+ declare function getDefSQL(tableName: string, cols: Record<string, AnyColumn>, schema?: string): string;
349
349
 
350
350
  type WhereArg<Cols extends Record<string, unknown>> = WhereInput<Cols> | [keyof Cols & string, string, unknown];
351
351
  declare class Table<T extends Record<string, AnyColumn>> {
@@ -1647,6 +1647,6 @@ interface MigrationStatement {
1647
1647
  * { users: usersTable, posts: postsTable },
1648
1648
  * );
1649
1649
  */
1650
- declare function generateMigration(prev: SchemaMap, next: SchemaMap): string;
1650
+ declare function generateMigration(prev: SchemaMap, next: SchemaMap, schema?: string): string;
1651
1651
 
1652
1652
  export { ARITHMETIC_OPERATORS, type AnyColumn, type AnyOperator, type ArithmeticOperator, BINARY_OPERATORS, type BinaryOperator, type BuiltCol, COMPARISON_OPERATORS, type ChangeEvent, Column, type ComparisonOperator, Database, type Expr, type InferSchema, JSON_OPERATORS, type JsonOperator, type ListenFn, type MigrationStatement, OPERATORS, type Prettify, type Restrict, type SchemaMap, type SetFlag, Table, UNARY_FILTER_OPERATORS, UNARY_OPERATORS, type UnaryOperator, type WhereCondition, type WhereInput, type WhereNode, add, array, bang, between, betweenSymmetric, bool, buildWhere, bytea, containedBy, contains, createFluentBuilder, distance, eq, eqq, float, generateMigration, getDefSQL, gt, gte, hasAllKeys, hasAnyKey, hasKey, ilike, inList, int, iregex, is, isDistinct, isNot, isNotDistinct, json, like, lt, lte, match, neq, neqAlt, notGt, notIlike, notIn, notIregex, notLike, notLt, notRegex, nullSafeEq, op, overlaps, regex, regexp, startsWith, table, text, time, timestamp, tsMatch, tsPhrase, unary, uuid, vector };
package/dist/index.js CHANGED
@@ -285,7 +285,7 @@ var vector = (dimension) => {
285
285
  var table = (cols) => {
286
286
  return cols;
287
287
  };
288
- function getDefSQL(tableName, cols) {
288
+ function getDefSQL(tableName, cols, schema) {
289
289
  const formatDefault2 = (def) => {
290
290
  if (typeof def === "string") return `'${def.replace(/'/g, "''")}'`;
291
291
  if (typeof def === "boolean") return def ? "true" : "false";
@@ -315,7 +315,7 @@ function getDefSQL(tableName, cols) {
315
315
  }
316
316
  return " " + parts.join(" ");
317
317
  });
318
- return `CREATE TABLE IF NOT EXISTS "${tableName}" (
318
+ return `CREATE TABLE IF NOT EXISTS ${schema ? schema + "." : ""}"${tableName}" (
319
319
  ${columns.join(",\n")}
320
320
  );`;
321
321
  }
@@ -602,10 +602,8 @@ var init = async (db, client, tables, isPGlite) => {
602
602
  FOR EACH ROW EXECUTE FUNCTION notify_table_change();
603
603
  `;
604
604
  if (isPGlite) {
605
- await client.query(tableSQL);
606
605
  await client.query(triggerSQL);
607
606
  } else {
608
- await sql2.raw(tableSQL).execute(db);
609
607
  await sql2.raw(triggerSQL).execute(db);
610
608
  }
611
609
  }
@@ -814,7 +812,7 @@ function diffTable(tableName, prevCols, nextCols) {
814
812
  }
815
813
  return stmts;
816
814
  }
817
- function generateMigration(prev, next) {
815
+ function generateMigration(prev, next, schema) {
818
816
  const stmts = [];
819
817
  const prevTables = new Set(Object.keys(prev));
820
818
  const nextTables = new Set(Object.keys(next));
@@ -828,22 +826,10 @@ function generateMigration(prev, next) {
828
826
  }
829
827
  for (const table2 of nextTables) {
830
828
  if (!prevTables.has(table2)) {
831
- const cols = next[table2];
832
- const colDefs = Object.entries(cols).map(([colName, col]) => {
833
- const def = build(col);
834
- const parts = [`"${colName}"`, def.SQlType ?? "text"];
835
- if (def.primaryKey) parts.push("PRIMARY KEY");
836
- if (def.notnull) parts.push("NOT NULL");
837
- if (def.unique) parts.push("UNIQUE");
838
- const defaultExpr = resolveDefault(def);
839
- if (defaultExpr !== void 0) parts.push(`DEFAULT ${defaultExpr}`);
840
- return " " + parts.join(" ");
841
- }).join(",\n");
829
+ const sql3 = getDefSQL(table2, next[table2], schema);
842
830
  stmts.push({
843
831
  kind: "create_table",
844
- sql: `CREATE TABLE IF NOT EXISTS "${table2}" (
845
- ${colDefs}
846
- );`
832
+ sql: sql3
847
833
  });
848
834
  }
849
835
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/optima-pg",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "author": "Inflector",
6
6
  "main": "./dist/index.js",