@inflector/optima-pg 1.0.3 → 1.0.4

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
  }
@@ -814,7 +814,7 @@ function diffTable(tableName, prevCols, nextCols) {
814
814
  }
815
815
  return stmts;
816
816
  }
817
- function generateMigration(prev, next) {
817
+ function generateMigration(prev, next, schema) {
818
818
  const stmts = [];
819
819
  const prevTables = new Set(Object.keys(prev));
820
820
  const nextTables = new Set(Object.keys(next));
@@ -828,22 +828,10 @@ function generateMigration(prev, next) {
828
828
  }
829
829
  for (const table2 of nextTables) {
830
830
  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");
831
+ const sql3 = getDefSQL(table2, next[table2], schema);
842
832
  stmts.push({
843
833
  kind: "create_table",
844
- sql: `CREATE TABLE IF NOT EXISTS "${table2}" (
845
- ${colDefs}
846
- );`
834
+ sql: sql3
847
835
  });
848
836
  }
849
837
  }
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.4",
4
4
  "type": "module",
5
5
  "author": "Inflector",
6
6
  "main": "./dist/index.js",