sql - nodef/food-ins GitHub Wiki

Gives commands to insert data to SQL database.

foodins.sql([table], [options]);
// table: name of database table (food_ins)
// options: table config
// .pk: primary key column (code)
// .index: create index (true)
// .tsvector: text search vector (code: 'A', names: 'B', type: 'C', status: 'C')
// --> 'sql commands'
const foodins = require('food-ins');

foodins.sql();
// 'CREATE TABLE IF NOT EXISTS "food_ins" ("code" TEXT, "names" TEXT, "type" TEXT, "status" TEXT, PRIMARY KEY("code"));\n' +
// 'INSERT INTO "food_ins" ("code", "names", "type", "status") VALUES\n' +
// '($$100$$, $$curcumins$$, $$colour$$, $$a e u$$),\n' +
// '($$100(i)$$, $$curcumin$$, $$colour (yellow and orange)$$, $$a e u$$),\n' +
// ...
// 'ON CONFLICT ("code") DO NOTHING;\n' +
// `CREATE OR REPLACE VIEW "food_ins_tsvector" AS SELECT *, setweight(to_tsvector('english', "code"), 'A')||setweight(to_tsvector('english', "names"), 'B')||setweight(to_tsvector('english', "type"), 'C')||setweight(to_tsvector('english', "status"), 'C') AS "tsvector" FROM "food_ins";\n` +   
// `CREATE INDEX IF NOT EXISTS "food_ins_tsvector_idx" ON "food_ins" USING GIN ((setweight(to_tsvector('english', "code"), 'A')||setweight(to_tsvector('english', "names"), 'B')||setweight(to_tsvector('english', "type"), 'C')||setweight(to_tsvector('english', "status"), 'C')));\n` +
// 'CREATE INDEX IF NOT EXISTS "food_ins_names_idx" ON "food_ins" ("names");\n' +
// 'CREATE INDEX IF NOT EXISTS "food_ins_type_idx" ON "food_ins" ("type");\n' +
// 'CREATE INDEX IF NOT EXISTS "food_ins_status_idx" ON "food_ins" ("status");\n'