nexusql 0.9.6 → 0.9.8

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
@@ -3216,13 +3216,15 @@ var Database = class _Database {
3216
3216
  async installExtensions(extensions) {
3217
3217
  for (const ext of extensions) {
3218
3218
  try {
3219
- await this.exec(`CREATE EXTENSION IF NOT EXISTS ${ext};`);
3219
+ const needsQuoting = /[^a-z0-9_]/i.test(ext);
3220
+ const quotedExt = needsQuoting ? `"${ext}"` : ext;
3221
+ await this.exec(`CREATE EXTENSION IF NOT EXISTS ${quotedExt};`);
3220
3222
  const result = await this.queryParams(
3221
3223
  `SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = $1) as exists`,
3222
3224
  [ext]
3223
3225
  );
3224
3226
  if (!result.rows[0]?.exists) {
3225
- throw new Error(`Extension "${ext}" was not installed`);
3227
+ throw new Error(`Extension ${quotedExt} was not installed`);
3226
3228
  }
3227
3229
  } catch (error) {
3228
3230
  const message = error instanceof Error ? error.message : String(error);
@@ -3412,8 +3414,16 @@ async function gen(options = {}) {
3412
3414
  const tempDb = db.withDatabase(tempDbName);
3413
3415
  let migrationSql = "";
3414
3416
  try {
3417
+ const hasVectorType = targetSql.toLowerCase().includes("vector");
3418
+ const extensions = [...config.extensions];
3419
+ if (hasVectorType && !extensions.includes("vector")) {
3420
+ spinner.info(
3421
+ "Detected 'vector' type usage - auto-enabling vector extension"
3422
+ );
3423
+ extensions.push("vector");
3424
+ }
3415
3425
  spinner.start("Installing extensions...");
3416
- await tempDb.installExtensions(config.extensions);
3426
+ await tempDb.installExtensions(extensions);
3417
3427
  if (config.extensions.includes("vector")) {
3418
3428
  const vectorCheck = await tempDb.query(
3419
3429
  "SELECT typname FROM pg_type WHERE typname = 'vector'"
@@ -3428,9 +3438,7 @@ async function gen(options = {}) {
3428
3438
  spinner.succeed("Installed db extensions");
3429
3439
  spinner.start("Loading schema into temp database...");
3430
3440
  if (targetSql.toLowerCase().includes("vector")) {
3431
- const vectorLines = targetSql.split("\n").filter(
3432
- (line) => line.toLowerCase().includes("vector")
3433
- );
3441
+ const vectorLines = targetSql.split("\n").filter((line) => line.toLowerCase().includes("vector"));
3434
3442
  console.log("\n[DEBUG] SQL lines with 'vector':");
3435
3443
  vectorLines.forEach((line) => console.log(" ", line.trim()));
3436
3444
  console.log("");