@saltcorn/postgres 1.1.1-beta.8 → 1.1.1-rc.2

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/postgres.js +29 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/postgres",
3
- "version": "1.1.1-beta.8",
3
+ "version": "1.1.1-rc.2",
4
4
  "description": "Postgres structures for Saltcorn, open-source no-code platform",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "scripts": {
@@ -12,7 +12,7 @@
12
12
  "license": "MIT",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
- "@saltcorn/db-common": "1.1.1-beta.8",
15
+ "@saltcorn/db-common": "1.1.1-rc.2",
16
16
  "pg": "^8.2.1",
17
17
  "pg-copy-streams": "^5.1.1",
18
18
  "replacestream": "4.0.3"
package/postgres.js CHANGED
@@ -408,6 +408,33 @@ const add_index = async (table_name, field_name) => {
408
408
  await pool.query(sql);
409
409
  };
410
410
 
411
+ /**
412
+ * Add Full-text search index
413
+ * @param {string} table_name - table name
414
+ * @param {string} field_name - list of columns (members of constraint)
415
+ * @returns {Promise<void>} no result
416
+ */
417
+ const add_fts_index = async (table_name, field_expression, language) => {
418
+ // TBD check that there are no problems with lenght of constraint name
419
+ const sql = `create index "${sqlsanitize(
420
+ table_name
421
+ )}_fts_index" on "${getTenantSchema()}"."${sqlsanitize(
422
+ table_name
423
+ )}" USING GIN (to_tsvector('${
424
+ language || "english"
425
+ }', ${field_expression}));`;
426
+ sql_log(sql);
427
+ await pool.query(sql);
428
+ };
429
+ const drop_fts_index = async (table_name) => {
430
+ // TBD check that there are no problems with lenght of constraint name
431
+ const sql = `drop index "${getTenantSchema()}"."${sqlsanitize(
432
+ table_name
433
+ )}_fts_index";`;
434
+ sql_log(sql);
435
+ await pool.query(sql);
436
+ };
437
+
411
438
  /**
412
439
  * Add index
413
440
  * @param {string} table_name - table name
@@ -530,12 +557,14 @@ const postgresExports = {
530
557
  changeConnection,
531
558
  set_sql_logging,
532
559
  get_sql_logging,
560
+ drop_fts_index,
533
561
  getClient,
534
562
  mkWhere,
535
563
  drop_reset_schema,
536
564
  add_unique_constraint,
537
565
  drop_unique_constraint,
538
566
  add_index,
567
+ add_fts_index,
539
568
  drop_index,
540
569
  reset_sequence,
541
570
  getVersion,