@bungres/kit 0.1.1 → 0.3.0

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/cli.js CHANGED
@@ -41,7 +41,7 @@ async function loadConfig(cwd = process.cwd()) {
41
41
  // src/commands/push.ts
42
42
  import * as fs from "fs";
43
43
 
44
- // ../bungres-orm/src/table.ts
44
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/table.ts
45
45
  var TableConfigSymbol = Symbol.for("BungresTableConfig");
46
46
  function getTableConfig(table) {
47
47
  return table[TableConfigSymbol];
@@ -81,7 +81,7 @@ function createTableFactory(casing) {
81
81
  var table = createTableFactory("none");
82
82
  var snakeCase = { table: createTableFactory("snake") };
83
83
  var camelCase = { table: createTableFactory("camel") };
84
- // ../bungres-orm/src/column.ts
84
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/column.ts
85
85
  function buildColumn(dataType, nameOrOpts, opts) {
86
86
  let name = "";
87
87
  let options = opts;
@@ -135,7 +135,7 @@ var interval = col("interval");
135
135
  var inet = col("inet");
136
136
  var cidr = col("cidr");
137
137
  var macaddr = col("macaddr");
138
- // ../bungres-orm/src/sql.ts
138
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/sql.ts
139
139
  function sqlJoin(chunks, separator = ", ") {
140
140
  const params = [];
141
141
  const parts = [];
@@ -146,7 +146,7 @@ function sqlJoin(chunks, separator = ", ") {
146
146
  }
147
147
  return { sql: parts.join(separator), params };
148
148
  }
149
- // ../bungres-orm/src/query.ts
149
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/query.ts
150
150
  class SelectBuilder {
151
151
  _table;
152
152
  _executor;
@@ -424,7 +424,7 @@ class DeleteBuilder {
424
424
  return { sql: query, params };
425
425
  }
426
426
  }
427
- // ../bungres-orm/src/relational.ts
427
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/relational.ts
428
428
  var _relationsCache = new WeakMap;
429
429
 
430
430
  class RelationalQueryBuilder {
@@ -651,7 +651,7 @@ class RelationalQueryBuilder {
651
651
  }
652
652
  }
653
653
 
654
- // ../bungres-orm/src/db.ts
654
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/db.ts
655
655
  function parseDBName(url) {
656
656
  try {
657
657
  return new URL(url).pathname.slice(1);
@@ -817,7 +817,7 @@ function createDB(config2) {
817
817
  }
818
818
  return db2;
819
819
  }
820
- // ../bungres-orm/src/ddl.ts
820
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/ddl.ts
821
821
  function generateCreateTable(config2, ifNotExists = true) {
822
822
  const tableName = config2.schema ? `"${config2.schema}"."${config2.name}"` : `"${config2.name}"`;
823
823
  const exists = ifNotExists ? " IF NOT EXISTS" : "";
@@ -1467,21 +1467,22 @@ function generateSchemaTS(tableMap, dbSchema) {
1467
1467
  `// Generated at: ${new Date().toISOString()}`,
1468
1468
  ``,
1469
1469
  `import {`,
1470
- ` table,`,
1470
+ ` snakeCase,`,
1471
1471
  ` text, varchar, char, integer, bigint, smallint,`,
1472
1472
  ` serial, bigserial, boolean, real, doublePrecision,`,
1473
1473
  ` numeric, decimal, json, jsonb,`,
1474
1474
  ` timestamp, timestamptz, date, time, uuid,`,
1475
1475
  ` bytea, inet,`,
1476
+ ` textArray, integerArray, varcharArray, uuidArray,`,
1476
1477
  `} from "@bungres/orm";`,
1477
1478
  ``
1478
1479
  ];
1479
1480
  for (const [, table2] of tableMap) {
1480
1481
  const varName = toCamelCase(table2.tableName);
1481
- lines.push(`export const ${varName} = table("${table2.tableName}", {`);
1482
+ lines.push(`export const ${varName} = snakeCase.table("${table2.tableName}", {`);
1482
1483
  for (const col2 of table2.columns) {
1483
1484
  const colExpr = buildColumnExpression(col2);
1484
- lines.push(` ${col2.name}: ${colExpr},`);
1485
+ lines.push(` ${toCamelCase(col2.name)}: ${colExpr},`);
1485
1486
  }
1486
1487
  const options = [];
1487
1488
  if (dbSchema !== "public") {
@@ -1528,84 +1529,97 @@ function generateSchemaTS(tableMap, dbSchema) {
1528
1529
  `);
1529
1530
  }
1530
1531
  function buildColumnExpression(col2) {
1531
- let expr = pgTypeToBungresBuilder(col2);
1532
+ const opts = [];
1533
+ if (col2.dataType === "character varying" || col2.dataType === "character") {
1534
+ if (col2.maxLength)
1535
+ opts.push(`length: ${col2.maxLength}`);
1536
+ }
1532
1537
  if (col2.isPrimary)
1533
- expr += `.primaryKey()`;
1538
+ opts.push(`primaryKey: true`);
1534
1539
  else if (!col2.isNullable)
1535
- expr += `.notNull()`;
1540
+ opts.push(`notNull: true`);
1536
1541
  if (col2.isUnique && !col2.isPrimary)
1537
- expr += `.unique()`;
1542
+ opts.push(`unique: true`);
1538
1543
  if (col2.columnDefault !== null && !col2.isPrimary) {
1539
1544
  if (col2.columnDefault.includes("(")) {
1540
- expr += `.defaultRaw("${col2.columnDefault}")`;
1541
- } else if (col2.dataType === "boolean") {
1542
- expr += `.default(${col2.columnDefault})`;
1543
- } else if (col2.dataType.includes("int") || col2.dataType.includes("numeric") || col2.dataType.includes("real") || col2.dataType.includes("double")) {
1544
- expr += `.default(${col2.columnDefault})`;
1545
+ opts.push(`defaultRaw: "${col2.columnDefault}"`);
1546
+ } else if (col2.dataType === "boolean" || col2.dataType.includes("int") || col2.dataType.includes("numeric") || col2.dataType.includes("real") || col2.dataType.includes("double")) {
1547
+ opts.push(`default: ${col2.columnDefault}`);
1545
1548
  } else {
1546
1549
  const cleaned = col2.columnDefault.replace(/^'(.*)'::.*$/, "$1");
1547
- expr += `.default("${cleaned}")`;
1550
+ opts.push(`default: "${cleaned}"`);
1548
1551
  }
1549
1552
  }
1550
1553
  if (col2.foreignTable && col2.foreignColumn) {
1551
1554
  const deleteRule = col2.deleteRule?.toLowerCase().replace(" ", " ");
1552
1555
  const updateRule = col2.updateRule?.toLowerCase().replace(" ", " ");
1553
- let refOpts = "";
1554
- if (deleteRule && deleteRule !== "no action") {
1555
- refOpts += `onDelete: "${deleteRule}", `;
1556
- }
1557
- if (updateRule && updateRule !== "no action") {
1558
- refOpts += `onUpdate: "${updateRule}"`;
1559
- }
1560
- const opts = refOpts ? `, { ${refOpts.trim().replace(/,$/, "")} }` : "";
1561
- expr += `.references("${col2.foreignTable}", "${col2.foreignColumn}"${opts})`;
1562
- }
1563
- return expr;
1556
+ let refOpts = `table: "${col2.foreignTable}", column: "${col2.foreignColumn}"`;
1557
+ if (deleteRule && deleteRule !== "no action")
1558
+ refOpts += `, onDelete: "${deleteRule}"`;
1559
+ if (updateRule && updateRule !== "no action")
1560
+ refOpts += `, onUpdate: "${updateRule}"`;
1561
+ opts.push(`references: { ${refOpts} }`);
1562
+ }
1563
+ let builderName = pgTypeToBungresBuilderName(col2);
1564
+ if (opts.length > 0) {
1565
+ return `${builderName}({ ${opts.join(", ")} })`;
1566
+ }
1567
+ return `${builderName}()`;
1564
1568
  }
1565
- function pgTypeToBungresBuilder(col2) {
1569
+ function pgTypeToBungresBuilderName(col2) {
1566
1570
  const dt = col2.dataType;
1567
- const name = col2.name;
1568
1571
  if (dt === "uuid")
1569
- return `uuid("${name}")`;
1572
+ return "uuid";
1570
1573
  if (dt === "text")
1571
- return `text("${name}")`;
1574
+ return "text";
1572
1575
  if (dt === "character varying")
1573
- return col2.maxLength ? `varchar("${name}", ${col2.maxLength})` : `varchar("${name}")`;
1576
+ return "varchar";
1574
1577
  if (dt === "character")
1575
- return col2.maxLength ? `char("${name}", ${col2.maxLength})` : `char("${name}")`;
1578
+ return "char";
1576
1579
  if (dt === "integer")
1577
- return `integer("${name}")`;
1580
+ return "integer";
1578
1581
  if (dt === "bigint")
1579
- return `bigint("${name}")`;
1582
+ return "bigint";
1580
1583
  if (dt === "smallint")
1581
- return `smallint("${name}")`;
1584
+ return "smallint";
1582
1585
  if (dt === "boolean")
1583
- return `boolean("${name}")`;
1586
+ return "boolean";
1584
1587
  if (dt === "real")
1585
- return `real("${name}")`;
1588
+ return "real";
1586
1589
  if (dt === "double precision")
1587
- return `doublePrecision("${name}")`;
1590
+ return "doublePrecision";
1588
1591
  if (dt === "numeric" || dt === "decimal")
1589
- return `numeric("${name}")`;
1592
+ return "numeric";
1590
1593
  if (dt === "json")
1591
- return `json("${name}")`;
1594
+ return "json";
1592
1595
  if (dt === "jsonb")
1593
- return `jsonb("${name}")`;
1596
+ return "jsonb";
1594
1597
  if (dt === "timestamp without time zone")
1595
- return `timestamp("${name}")`;
1598
+ return "timestamp";
1596
1599
  if (dt === "timestamp with time zone")
1597
- return `timestamptz("${name}")`;
1600
+ return "timestamptz";
1598
1601
  if (dt === "date")
1599
- return `date("${name}")`;
1602
+ return "date";
1600
1603
  if (dt === "time without time zone")
1601
- return `time("${name}")`;
1604
+ return "time";
1602
1605
  if (dt === "bytea")
1603
- return `bytea("${name}")`;
1606
+ return "bytea";
1604
1607
  if (dt === "inet")
1605
- return `inet("${name}")`;
1608
+ return "inet";
1606
1609
  if (dt === "USER-DEFINED" && col2.udtName === "citext")
1607
- return `text("${name}")`;
1608
- return `text("${name}") /* original type: ${dt} */`;
1610
+ return "text";
1611
+ if (dt === "ARRAY") {
1612
+ if (col2.udtName === "_text")
1613
+ return "textArray";
1614
+ if (col2.udtName === "_int4" || col2.udtName === "_int8")
1615
+ return "integerArray";
1616
+ if (col2.udtName === "_varchar")
1617
+ return "varcharArray";
1618
+ if (col2.udtName === "_uuid")
1619
+ return "uuidArray";
1620
+ return "textArray";
1621
+ }
1622
+ return "text";
1609
1623
  }
1610
1624
  function toCamelCase(str) {
1611
1625
  return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ async function loadConfig(cwd = process.cwd()) {
38
38
  // src/schema-loader.ts
39
39
  import { resolve as resolve2, join as join2 } from "path";
40
40
 
41
- // ../bungres-orm/src/table.ts
41
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/table.ts
42
42
  var TableConfigSymbol = Symbol.for("BungresTableConfig");
43
43
  function getTableConfig(table) {
44
44
  return table[TableConfigSymbol];
@@ -78,7 +78,7 @@ function createTableFactory(casing) {
78
78
  var table = createTableFactory("none");
79
79
  var snakeCase = { table: createTableFactory("snake") };
80
80
  var camelCase = { table: createTableFactory("camel") };
81
- // ../bungres-orm/src/column.ts
81
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/column.ts
82
82
  function buildColumn(dataType, nameOrOpts, opts) {
83
83
  let name = "";
84
84
  let options = opts;
@@ -132,7 +132,7 @@ var interval = col("interval");
132
132
  var inet = col("inet");
133
133
  var cidr = col("cidr");
134
134
  var macaddr = col("macaddr");
135
- // ../bungres-orm/src/sql.ts
135
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/sql.ts
136
136
  function sqlJoin(chunks, separator = ", ") {
137
137
  const params = [];
138
138
  const parts = [];
@@ -143,7 +143,7 @@ function sqlJoin(chunks, separator = ", ") {
143
143
  }
144
144
  return { sql: parts.join(separator), params };
145
145
  }
146
- // ../bungres-orm/src/query.ts
146
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/query.ts
147
147
  class SelectBuilder {
148
148
  _table;
149
149
  _executor;
@@ -421,7 +421,7 @@ class DeleteBuilder {
421
421
  return { sql: query, params };
422
422
  }
423
423
  }
424
- // ../bungres-orm/src/relational.ts
424
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/relational.ts
425
425
  var _relationsCache = new WeakMap;
426
426
 
427
427
  class RelationalQueryBuilder {
@@ -648,7 +648,7 @@ class RelationalQueryBuilder {
648
648
  }
649
649
  }
650
650
 
651
- // ../bungres-orm/src/db.ts
651
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/db.ts
652
652
  function parseDBName(url) {
653
653
  try {
654
654
  return new URL(url).pathname.slice(1);
@@ -814,7 +814,7 @@ function createDB(config) {
814
814
  }
815
815
  return db;
816
816
  }
817
- // ../bungres-orm/src/ddl.ts
817
+ // ../../node_modules/.bun/@bungres+orm@0.2.0/node_modules/@bungres/orm/src/ddl.ts
818
818
  function generateCreateTable(config, ifNotExists = true) {
819
819
  const tableName = config.schema ? `"${config.schema}"."${config.name}"` : `"${config.name}"`;
820
820
  const exists = ifNotExists ? " IF NOT EXISTS" : "";
@@ -1462,21 +1462,22 @@ function generateSchemaTS(tableMap, dbSchema) {
1462
1462
  `// Generated at: ${new Date().toISOString()}`,
1463
1463
  ``,
1464
1464
  `import {`,
1465
- ` table,`,
1465
+ ` snakeCase,`,
1466
1466
  ` text, varchar, char, integer, bigint, smallint,`,
1467
1467
  ` serial, bigserial, boolean, real, doublePrecision,`,
1468
1468
  ` numeric, decimal, json, jsonb,`,
1469
1469
  ` timestamp, timestamptz, date, time, uuid,`,
1470
1470
  ` bytea, inet,`,
1471
+ ` textArray, integerArray, varcharArray, uuidArray,`,
1471
1472
  `} from "@bungres/orm";`,
1472
1473
  ``
1473
1474
  ];
1474
1475
  for (const [, table2] of tableMap) {
1475
1476
  const varName = toCamelCase(table2.tableName);
1476
- lines.push(`export const ${varName} = table("${table2.tableName}", {`);
1477
+ lines.push(`export const ${varName} = snakeCase.table("${table2.tableName}", {`);
1477
1478
  for (const col2 of table2.columns) {
1478
1479
  const colExpr = buildColumnExpression(col2);
1479
- lines.push(` ${col2.name}: ${colExpr},`);
1480
+ lines.push(` ${toCamelCase(col2.name)}: ${colExpr},`);
1480
1481
  }
1481
1482
  const options = [];
1482
1483
  if (dbSchema !== "public") {
@@ -1523,84 +1524,97 @@ function generateSchemaTS(tableMap, dbSchema) {
1523
1524
  `);
1524
1525
  }
1525
1526
  function buildColumnExpression(col2) {
1526
- let expr = pgTypeToBungresBuilder(col2);
1527
+ const opts = [];
1528
+ if (col2.dataType === "character varying" || col2.dataType === "character") {
1529
+ if (col2.maxLength)
1530
+ opts.push(`length: ${col2.maxLength}`);
1531
+ }
1527
1532
  if (col2.isPrimary)
1528
- expr += `.primaryKey()`;
1533
+ opts.push(`primaryKey: true`);
1529
1534
  else if (!col2.isNullable)
1530
- expr += `.notNull()`;
1535
+ opts.push(`notNull: true`);
1531
1536
  if (col2.isUnique && !col2.isPrimary)
1532
- expr += `.unique()`;
1537
+ opts.push(`unique: true`);
1533
1538
  if (col2.columnDefault !== null && !col2.isPrimary) {
1534
1539
  if (col2.columnDefault.includes("(")) {
1535
- expr += `.defaultRaw("${col2.columnDefault}")`;
1536
- } else if (col2.dataType === "boolean") {
1537
- expr += `.default(${col2.columnDefault})`;
1538
- } else if (col2.dataType.includes("int") || col2.dataType.includes("numeric") || col2.dataType.includes("real") || col2.dataType.includes("double")) {
1539
- expr += `.default(${col2.columnDefault})`;
1540
+ opts.push(`defaultRaw: "${col2.columnDefault}"`);
1541
+ } else if (col2.dataType === "boolean" || col2.dataType.includes("int") || col2.dataType.includes("numeric") || col2.dataType.includes("real") || col2.dataType.includes("double")) {
1542
+ opts.push(`default: ${col2.columnDefault}`);
1540
1543
  } else {
1541
1544
  const cleaned = col2.columnDefault.replace(/^'(.*)'::.*$/, "$1");
1542
- expr += `.default("${cleaned}")`;
1545
+ opts.push(`default: "${cleaned}"`);
1543
1546
  }
1544
1547
  }
1545
1548
  if (col2.foreignTable && col2.foreignColumn) {
1546
1549
  const deleteRule = col2.deleteRule?.toLowerCase().replace(" ", " ");
1547
1550
  const updateRule = col2.updateRule?.toLowerCase().replace(" ", " ");
1548
- let refOpts = "";
1549
- if (deleteRule && deleteRule !== "no action") {
1550
- refOpts += `onDelete: "${deleteRule}", `;
1551
- }
1552
- if (updateRule && updateRule !== "no action") {
1553
- refOpts += `onUpdate: "${updateRule}"`;
1554
- }
1555
- const opts = refOpts ? `, { ${refOpts.trim().replace(/,$/, "")} }` : "";
1556
- expr += `.references("${col2.foreignTable}", "${col2.foreignColumn}"${opts})`;
1557
- }
1558
- return expr;
1551
+ let refOpts = `table: "${col2.foreignTable}", column: "${col2.foreignColumn}"`;
1552
+ if (deleteRule && deleteRule !== "no action")
1553
+ refOpts += `, onDelete: "${deleteRule}"`;
1554
+ if (updateRule && updateRule !== "no action")
1555
+ refOpts += `, onUpdate: "${updateRule}"`;
1556
+ opts.push(`references: { ${refOpts} }`);
1557
+ }
1558
+ let builderName = pgTypeToBungresBuilderName(col2);
1559
+ if (opts.length > 0) {
1560
+ return `${builderName}({ ${opts.join(", ")} })`;
1561
+ }
1562
+ return `${builderName}()`;
1559
1563
  }
1560
- function pgTypeToBungresBuilder(col2) {
1564
+ function pgTypeToBungresBuilderName(col2) {
1561
1565
  const dt = col2.dataType;
1562
- const name = col2.name;
1563
1566
  if (dt === "uuid")
1564
- return `uuid("${name}")`;
1567
+ return "uuid";
1565
1568
  if (dt === "text")
1566
- return `text("${name}")`;
1569
+ return "text";
1567
1570
  if (dt === "character varying")
1568
- return col2.maxLength ? `varchar("${name}", ${col2.maxLength})` : `varchar("${name}")`;
1571
+ return "varchar";
1569
1572
  if (dt === "character")
1570
- return col2.maxLength ? `char("${name}", ${col2.maxLength})` : `char("${name}")`;
1573
+ return "char";
1571
1574
  if (dt === "integer")
1572
- return `integer("${name}")`;
1575
+ return "integer";
1573
1576
  if (dt === "bigint")
1574
- return `bigint("${name}")`;
1577
+ return "bigint";
1575
1578
  if (dt === "smallint")
1576
- return `smallint("${name}")`;
1579
+ return "smallint";
1577
1580
  if (dt === "boolean")
1578
- return `boolean("${name}")`;
1581
+ return "boolean";
1579
1582
  if (dt === "real")
1580
- return `real("${name}")`;
1583
+ return "real";
1581
1584
  if (dt === "double precision")
1582
- return `doublePrecision("${name}")`;
1585
+ return "doublePrecision";
1583
1586
  if (dt === "numeric" || dt === "decimal")
1584
- return `numeric("${name}")`;
1587
+ return "numeric";
1585
1588
  if (dt === "json")
1586
- return `json("${name}")`;
1589
+ return "json";
1587
1590
  if (dt === "jsonb")
1588
- return `jsonb("${name}")`;
1591
+ return "jsonb";
1589
1592
  if (dt === "timestamp without time zone")
1590
- return `timestamp("${name}")`;
1593
+ return "timestamp";
1591
1594
  if (dt === "timestamp with time zone")
1592
- return `timestamptz("${name}")`;
1595
+ return "timestamptz";
1593
1596
  if (dt === "date")
1594
- return `date("${name}")`;
1597
+ return "date";
1595
1598
  if (dt === "time without time zone")
1596
- return `time("${name}")`;
1599
+ return "time";
1597
1600
  if (dt === "bytea")
1598
- return `bytea("${name}")`;
1601
+ return "bytea";
1599
1602
  if (dt === "inet")
1600
- return `inet("${name}")`;
1603
+ return "inet";
1601
1604
  if (dt === "USER-DEFINED" && col2.udtName === "citext")
1602
- return `text("${name}")`;
1603
- return `text("${name}") /* original type: ${dt} */`;
1605
+ return "text";
1606
+ if (dt === "ARRAY") {
1607
+ if (col2.udtName === "_text")
1608
+ return "textArray";
1609
+ if (col2.udtName === "_int4" || col2.udtName === "_int8")
1610
+ return "integerArray";
1611
+ if (col2.udtName === "_varchar")
1612
+ return "varcharArray";
1613
+ if (col2.udtName === "_uuid")
1614
+ return "uuidArray";
1615
+ return "textArray";
1616
+ }
1617
+ return "text";
1604
1618
  }
1605
1619
  function toCamelCase(str) {
1606
1620
  return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bungres/kit",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "CLI toolkit for @bungres/orm — migrate, push, generate, pull",
5
5
  "type": "module",
6
6
  "bin": {
@@ -194,23 +194,24 @@ function generateSchemaTS(
194
194
  `// Generated at: ${new Date().toISOString()}`,
195
195
  ``,
196
196
  `import {`,
197
- ` table,`,
197
+ ` snakeCase,`,
198
198
  ` text, varchar, char, integer, bigint, smallint,`,
199
199
  ` serial, bigserial, boolean, real, doublePrecision,`,
200
200
  ` numeric, decimal, json, jsonb,`,
201
201
  ` timestamp, timestamptz, date, time, uuid,`,
202
202
  ` bytea, inet,`,
203
+ ` textArray, integerArray, varcharArray, uuidArray,`,
203
204
  `} from "@bungres/orm";`,
204
205
  ``,
205
206
  ];
206
207
 
207
208
  for (const [, table] of tableMap) {
208
209
  const varName = toCamelCase(table.tableName);
209
- lines.push(`export const ${varName} = table("${table.tableName}", {`);
210
+ lines.push(`export const ${varName} = snakeCase.table("${table.tableName}", {`);
210
211
 
211
212
  for (const col of table.columns) {
212
213
  const colExpr = buildColumnExpression(col);
213
- lines.push(` ${col.name}: ${colExpr},`);
214
+ lines.push(` ${toCamelCase(col.name)}: ${colExpr},`);
214
215
  }
215
216
 
216
217
  // Third argument: Table options (schema, indexes)
@@ -260,78 +261,77 @@ function generateSchemaTS(
260
261
  }
261
262
 
262
263
  function buildColumnExpression(col: TableInfo["columns"][number]): string {
263
- let expr = pgTypeToBungresBuilder(col);
264
+ const opts: string[] = [];
264
265
 
265
- if (col.isPrimary) expr += `.primaryKey()`;
266
- else if (!col.isNullable) expr += `.notNull()`;
266
+ if (col.dataType === "character varying" || col.dataType === "character") {
267
+ if (col.maxLength) opts.push(`length: ${col.maxLength}`);
268
+ }
269
+
270
+ if (col.isPrimary) opts.push(`primaryKey: true`);
271
+ else if (!col.isNullable) opts.push(`notNull: true`);
267
272
 
268
- if (col.isUnique && !col.isPrimary) expr += `.unique()`;
273
+ if (col.isUnique && !col.isPrimary) opts.push(`unique: true`);
269
274
 
270
275
  if (col.columnDefault !== null && !col.isPrimary) {
271
276
  if (col.columnDefault.includes("(")) {
272
- // Function call — raw
273
- expr += `.defaultRaw("${col.columnDefault}")`;
274
- } else if (col.dataType === "boolean") {
275
- expr += `.default(${col.columnDefault})`;
276
- } else if (
277
- col.dataType.includes("int") ||
278
- col.dataType.includes("numeric") ||
279
- col.dataType.includes("real") ||
280
- col.dataType.includes("double")
281
- ) {
282
- expr += `.default(${col.columnDefault})`;
277
+ opts.push(`defaultRaw: "${col.columnDefault}"`);
278
+ } else if (col.dataType === "boolean" || col.dataType.includes("int") || col.dataType.includes("numeric") || col.dataType.includes("real") || col.dataType.includes("double")) {
279
+ opts.push(`default: ${col.columnDefault}`);
283
280
  } else {
284
- // Strip surrounding quotes for string defaults
285
281
  const cleaned = col.columnDefault.replace(/^'(.*)'::.*$/, "$1");
286
- expr += `.default("${cleaned}")`;
282
+ opts.push(`default: "${cleaned}"`);
287
283
  }
288
284
  }
289
285
 
290
286
  if (col.foreignTable && col.foreignColumn) {
291
287
  const deleteRule = col.deleteRule?.toLowerCase().replace(" ", " ");
292
288
  const updateRule = col.updateRule?.toLowerCase().replace(" ", " ");
293
- let refOpts = "";
294
- if (deleteRule && deleteRule !== "no action") {
295
- refOpts += `onDelete: "${deleteRule}", `;
296
- }
297
- if (updateRule && updateRule !== "no action") {
298
- refOpts += `onUpdate: "${updateRule}"`;
299
- }
300
- const opts = refOpts ? `, { ${refOpts.trim().replace(/,$/, "")} }` : "";
301
- expr += `.references("${col.foreignTable}", "${col.foreignColumn}"${opts})`;
289
+ let refOpts = `table: "${col.foreignTable}", column: "${col.foreignColumn}"`;
290
+ if (deleteRule && deleteRule !== "no action") refOpts += `, onDelete: "${deleteRule}"`;
291
+ if (updateRule && updateRule !== "no action") refOpts += `, onUpdate: "${updateRule}"`;
292
+ opts.push(`references: { ${refOpts} }`);
302
293
  }
303
294
 
304
- return expr;
295
+ let builderName = pgTypeToBungresBuilderName(col);
296
+
297
+ if (opts.length > 0) {
298
+ return `${builderName}({ ${opts.join(", ")} })`;
299
+ }
300
+ return `${builderName}()`;
305
301
  }
306
302
 
307
- function pgTypeToBungresBuilder(col: TableInfo["columns"][number]): string {
303
+ function pgTypeToBungresBuilderName(col: TableInfo["columns"][number]): string {
308
304
  const dt = col.dataType;
309
- const name = col.name;
310
-
311
- if (dt === "uuid") return `uuid("${name}")`;
312
- if (dt === "text") return `text("${name}")`;
313
- if (dt === "character varying")
314
- return col.maxLength ? `varchar("${name}", ${col.maxLength})` : `varchar("${name}")`;
315
- if (dt === "character")
316
- return col.maxLength ? `char("${name}", ${col.maxLength})` : `char("${name}")`;
317
- if (dt === "integer") return `integer("${name}")`;
318
- if (dt === "bigint") return `bigint("${name}")`;
319
- if (dt === "smallint") return `smallint("${name}")`;
320
- if (dt === "boolean") return `boolean("${name}")`;
321
- if (dt === "real") return `real("${name}")`;
322
- if (dt === "double precision") return `doublePrecision("${name}")`;
323
- if (dt === "numeric" || dt === "decimal") return `numeric("${name}")`;
324
- if (dt === "json") return `json("${name}")`;
325
- if (dt === "jsonb") return `jsonb("${name}")`;
326
- if (dt === "timestamp without time zone") return `timestamp("${name}")`;
327
- if (dt === "timestamp with time zone") return `timestamptz("${name}")`;
328
- if (dt === "date") return `date("${name}")`;
329
- if (dt === "time without time zone") return `time("${name}")`;
330
- if (dt === "bytea") return `bytea("${name}")`;
331
- if (dt === "inet") return `inet("${name}")`;
332
- if (dt === "USER-DEFINED" && col.udtName === "citext") return `text("${name}")`;
305
+
306
+ if (dt === "uuid") return "uuid";
307
+ if (dt === "text") return "text";
308
+ if (dt === "character varying") return "varchar";
309
+ if (dt === "character") return "char";
310
+ if (dt === "integer") return "integer";
311
+ if (dt === "bigint") return "bigint";
312
+ if (dt === "smallint") return "smallint";
313
+ if (dt === "boolean") return "boolean";
314
+ if (dt === "real") return "real";
315
+ if (dt === "double precision") return "doublePrecision";
316
+ if (dt === "numeric" || dt === "decimal") return "numeric";
317
+ if (dt === "json") return "json";
318
+ if (dt === "jsonb") return "jsonb";
319
+ if (dt === "timestamp without time zone") return "timestamp";
320
+ if (dt === "timestamp with time zone") return "timestamptz";
321
+ if (dt === "date") return "date";
322
+ if (dt === "time without time zone") return "time";
323
+ if (dt === "bytea") return "bytea";
324
+ if (dt === "inet") return "inet";
325
+ if (dt === "USER-DEFINED" && col.udtName === "citext") return "text";
326
+ if (dt === "ARRAY") {
327
+ if (col.udtName === "_text") return "textArray";
328
+ if (col.udtName === "_int4" || col.udtName === "_int8") return "integerArray";
329
+ if (col.udtName === "_varchar") return "varcharArray";
330
+ if (col.udtName === "_uuid") return "uuidArray";
331
+ return "textArray";
332
+ }
333
333
  // Fallback
334
- return `text("${name}") /* original type: ${dt} */`;
334
+ return "text";
335
335
  }
336
336
 
337
337
  function toCamelCase(str: string): string {