@m1212e/rumble 0.16.15 → 0.16.16

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/out/index.cjs CHANGED
@@ -949,6 +949,10 @@ async function initSearchIfApplicable(input) {
949
949
  const dbName = (await input.db.execute(drizzle_orm.sql`SELECT current_database()`)).rows[0].current_database;
950
950
  await input.db.execute(drizzle_orm.sql.raw(`ALTER DATABASE ${dbName} SET pg_trgm.similarity_threshold = ${threshold};`));
951
951
  }
952
+ if (input.search?.cpu_operator_cost) {
953
+ if (typeof input.search.cpu_operator_cost !== "number") throw new Error(`CPU operator cost must be a number`);
954
+ if (input.search.cpu_operator_cost <= 0) throw new Error(`CPU operator cost must be a positive number`);
955
+ }
952
956
  }
953
957
  /**
954
958
  * Performs adjustments to the query args to issue a full text search in case the
@@ -1274,8 +1278,8 @@ const createQueryImplementer = ({ db, schemaBuilder, search, whereArgImplementer
1274
1278
  if (mappedArgs.orderBy) filter.orderBy = mappedArgs.orderBy;
1275
1279
  const queryInstance = query(filter);
1276
1280
  if (filter.columns) queryInstance.columns = filter.columns;
1277
- if (search?.cpu_operator_cost) return db.transaction(async (tx) => {
1278
- if (isPostgresDB(tx)) await tx.execute(drizzle_orm.sql`SET LOCAL cpu_operator_cost = ${search.cpu_operator_cost};`);
1281
+ if (search?.enabled && args.search && args.search.length > 0 && search?.cpu_operator_cost) return db.transaction(async (tx) => {
1282
+ if (isPostgresDB(tx)) await tx.execute(drizzle_orm.sql.raw(`SET cpu_operator_cost = ${search.cpu_operator_cost};`));
1279
1283
  else console.info("Database dialect is not postgresql, cannot set cpu_operator_cost.");
1280
1284
  return tx.query[table].findMany(queryInstance);
1281
1285
  });