sql - nodef/food-e GitHub Wiki

Gives commands to insert data to SQL database.

foode.sql([table], [options]);
// table: name of database table (food_e)
// 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 foode = require('food-e');

foode.sql();
// 'CREATE TABLE IF NOT EXISTS "food_e" ("code" TEXT, "names" TEXT, "type" TEXT, "status" TEXT, PRIMARY KEY("code"));\n' +
// 'INSERT INTO "food_e" ("code", "names", "type", "status") VALUES\n' +
// '($$E100$$, $$Curcumin (from turmeric)$$, $$color (Yellow-orange)$$, $$e u$$),\n' +
// '($$E101$$, $$Riboflavin (Vitamin B2), formerly called lactoflavin$$, $$color (Yellow-orange)$$, $$e u$$),\n' +  
// ...
// 'ON CONFLICT ("code") DO NOTHING;\n' +
// `CREATE OR REPLACE VIEW "food_e_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_e";\n` +   
// `CREATE INDEX IF NOT EXISTS "food_e_tsvector_idx" ON "food_e" 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_e_names_idx" ON "food_e" ("names");\n' +
// 'CREATE INDEX IF NOT EXISTS "food_e_type_idx" ON "food_e" ("type");\n' +
// 'CREATE INDEX IF NOT EXISTS "food_e_status_idx" ON "food_e" ("status");\n'