|
1 | | -SQL is designed for managing or stream processing data in an RDBMS. |
| 1 | +[SQL] is designed for managing or stream processing data in an RDBMS. |
| 2 | +Includes SQL command generation functions, with a few for text matching (PostgreSQL). |
2 | 3 |
|
3 | 4 | ```javascript |
4 | | -const extra = require('sql-extra'); |
5 | | -// extra.createTable(<name>, <columns>, [options]) |
6 | | -// extra.createIndex(<name>, <table>, <expression>, [options]) |
7 | | -// ... |
| 5 | +const sql = require('extra-sql'); |
| 6 | + |
| 7 | +sql.tableExists('food'); |
| 8 | +// SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name='food'); |
| 9 | + |
| 10 | +sql.setupTable('food', {code: 'TEXT', name: 'TEXT'}, |
| 11 | + [{code: 'F1', name: 'Mango'}, {code: 'F2', name: 'Lychee'}]); |
| 12 | +// CREATE TABLE IF NOT EXISTS "food" ("code" TEXT, "name" TEXT); |
| 13 | +// INSERT INTO "food" ("code", "name") VALUES |
| 14 | +// ('F1', 'Mango'), |
| 15 | +// ('F2', 'Lychee'); |
| 16 | + |
| 17 | +sql.selectTsquery('columns', 'total fat'); |
| 18 | +// SELECT * FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat'); |
| 19 | + |
| 20 | +sql.matchTsquery('columns', ['total', 'fat']); |
| 21 | +// SELECT *, '2'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat') UNION ALL |
| 22 | +// SELECT *, '1'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total'); |
8 | 23 | ``` |
9 | 24 |
|
10 | | -Methods: |
11 | | -- [createTable](https://www.npmjs.com/package/@sql-extra/createtable) |
12 | | -- [createIndex](https://www.npmjs.com/package/@sql-extra/createindex) |
13 | | -- [createView](https://www.npmjs.com/package/@sql-extra/createview) |
14 | | -- [insertInto](https://www.npmjs.com/package/@sql-extra/insertinto) |
15 | | -- [setupTable](https://www.npmjs.com/package/@sql-extra/setuptable) |
16 | | -- [tableExists](https://www.npmjs.com/package/@sql-extra/tableexists) |
17 | | -- [selectTsquery](https://www.npmjs.com/package/@sql-extra/selecttsquery) |
18 | | -- [matchTsquery](https://www.npmjs.com/package/@sql-extra/matchtsquery) |
| 25 | +### reference |
| 26 | + |
| 27 | +| Name | Action |
| 28 | +|---------------------|------- |
| 29 | +| [createTable] | Generates SQL command for CREATE TABLE. |
| 30 | +| [createIndex] | Generates SQL command for CREATE INDEX. |
| 31 | +| [createView] | Generates SQL command for CREATE VIEW. |
| 32 | +| [insertInto] | Generates SQL command for INSERT INTO. |
| 33 | +| [setupTable] | Generates SQL commands to setup table (create, insert, index). |
| 34 | +| [tableExists] | Generates SQL command for table exists check. |
| 35 | +| [selectTsquery] | Generates SQL command for SELECT with tsquery. |
| 36 | +| [matchTsquery] | Generates SQL query for matching words with tsquery. |
| 37 | + |
| 38 | +<br> |
| 39 | +<br> |
| 40 | + |
| 41 | +[](https://nodef.github.io) |
| 42 | + |
| 43 | +[createTable]: https://github.com/nodef/extra-sql/wiki/createTable |
| 44 | +[createIndex]: https://github.com/nodef/extra-sql/wiki/createIndex |
| 45 | +[createView]: https://github.com/nodef/extra-sql/wiki/createView |
| 46 | +[insertInto]: https://github.com/nodef/extra-sql/wiki/insertInto |
| 47 | +[setupTable]: https://github.com/nodef/extra-sql/wiki/setupTable |
| 48 | +[tableExists]: https://github.com/nodef/extra-sql/wiki/tableExists |
| 49 | +[selectTsquery]: https://github.com/nodef/extra-sql/wiki/selectTsquery |
| 50 | +[matchTsquery]: https://github.com/nodef/extra-sql/wiki/matchTsquery |
| 51 | +[SQL]: https://en.wikipedia.org/wiki/SQL |
0 commit comments