Do you wish to register an account?
Browse Source

Merge branch 'develop'

master
Timothy Warren 5 years ago
parent
commit
cc6a3bb80b
  1. 29
      .editorconfig
  2. 5
      .gitignore
  3. 31
      .gitlab-ci.yml
  4. 9
      .istanbul.yml
  5. 7
      .jscsrc
  6. 473
      API.md
  7. 6
      CHANGELOG.md
  8. 19
      README.md
  9. 12
      docs/assets/bass-addons.css
  10. 1065
      docs/assets/bass.css
  11. BIN
      docs/assets/fonts/EOT/SourceCodePro-Bold.eot
  12. BIN
      docs/assets/fonts/EOT/SourceCodePro-Regular.eot
  13. 93
      docs/assets/fonts/LICENSE.txt
  14. BIN
      docs/assets/fonts/OTF/SourceCodePro-Bold.otf
  15. BIN
      docs/assets/fonts/OTF/SourceCodePro-Regular.otf
  16. BIN
      docs/assets/fonts/TTF/SourceCodePro-Bold.ttf
  17. BIN
      docs/assets/fonts/TTF/SourceCodePro-Regular.ttf
  18. BIN
      docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff
  19. BIN
      docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff
  20. BIN
      docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff
  21. BIN
      docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff
  22. BIN
      docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2
  23. BIN
      docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2
  24. BIN
      docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2
  25. BIN
      docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2
  26. 23
      docs/assets/fonts/source-code-pro.css
  27. 110
      docs/assets/site.js
  28. 135
      docs/assets/style.css
  29. 5792
      docs/index.html
  30. 87
      gulpfile.js
  31. 20
      lib/Adapter.js
  32. 65
      lib/Driver.js
  33. 20
      lib/NodeQuery.js
  34. 481
      lib/QueryBuilder.js
  35. 272
      lib/QueryBuilderBase.js
  36. 28
      lib/QueryParser.js
  37. 20
      lib/Result.js
  38. 4
      lib/State.js
  39. 8
      lib/adapters/Firebird/index.js
  40. 61
      lib/adapters/Firebird/node-firebird.js
  41. 0
      lib/adapters/MSSQLServer/index.js
  42. 3
      lib/adapters/MariaDB/index.js
  43. 71
      lib/adapters/Mysql.js
  44. 7
      lib/adapters/Mysql/index.js
  45. 52
      lib/adapters/Mysql/mysql2.js
  46. 46
      lib/adapters/Pg/Pg.js
  47. 7
      lib/adapters/Pg/index.js
  48. 64
      lib/adapters/Sqlite.js
  49. 67
      lib/adapters/Sqlite/dblite.js
  50. 10
      lib/adapters/Sqlite/index.js
  51. 63
      lib/adapters/Sqlite/sqlite3.js
  52. 45
      lib/drivers/Firebird.js
  53. 8
      lib/drivers/MariaDB.js
  54. 19
      lib/drivers/Mysql.js
  55. 4
      lib/drivers/Pg.js
  56. 20
      lib/drivers/Sqlite.js
  57. 21
      lib/helpers.js
  58. 54
      package.json
  59. 5
      sonar-project.properties
  60. BIN
      test/FB_TEST_DB.FDB
  61. 38
      test/adapters/00node-firebird_test.js
  62. 78
      test/adapters/dblite_test.js
  63. 74
      test/adapters/mysql2_test.js
  64. 75
      test/adapters/pg_test.js
  65. 63
      test/adapters/sqlite3_test.js
  66. 5
      test/base.js
  67. 230
      test/base/adapterCallbackTestRunner.js
  68. 42
      test/base/adapterPromiseTestRunner.js
  69. 101
      test/base/tests.js
  70. 15
      test/base_test.js
  71. 39
      test/config-ci.json
  72. 16
      test/docker_install.sh
  73. 28
      test/helpers_test.js
  74. 2
      test/mocha.opts
  75. 73
      test/query-parser_test.js
  76. 15
      test/sql/mssql.sql
  77. 5
      test/sql/mysql.sql
  78. 6
      test/sql/pgsql.sql

29
.editorconfig

@ -0,0 +1,29 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation
# Set default charset
[*]
charset = utf-8
# Tab indentation (no size specified)
[*]
indent_style = tab
indent_size = 4
# Indentation override for all JS under lib directory
[*.js]
indent_size = 2
# Matches the exact files either package.json or .travis.yml
[*.yml]
indent_style = space
indent_size = 2

5
.gitignore

@ -3,4 +3,7 @@ coverage
npm-debug.log
node_modules/*
.sonar/*
test/config.json
test/config.json
.DS_store
/.idea/
yarn.lock

31
.gitlab-ci.yml

@ -0,0 +1,31 @@
before_script:
# Install dependencies
- bash test/docker_install.sh > /dev/null
- npm install
services:
- mysql:latest
- postgres:latest
variables:
MYSQL_ROOT_PASSWORD: foo-bar-baz
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
POSTGRES_DB: test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- node_modules/
test:6:
image: node:6
script: npm run test
test:latest:
image: node:latest
script: npm run test

9
.istanbul.yml

@ -0,0 +1,9 @@
reporting:
print: summary
reports:
- lcov
- lcovonly
- clover
- html
- text
dir: ./coverage

7
.jscsrc

@ -1,7 +0,0 @@
{
"preset": "airbnb",
"validateIndentation": null,
"requireLineFeedAtFileEnd": null,
"disallowSpaceAfterPrefixUnaryOperators": null,
"disallowMultipleVarDecl": null
}

473
API.md

@ -1,10 +1,12 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
# NodeQuery
Class for connection management
**Parameters**
- `config` **object** connection parameters
- `config` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** connection parameters
## constructor
@ -12,7 +14,7 @@ Constructor
**Parameters**
- `config` **object** connection parameters
- `config` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** connection parameters
**Examples**
@ -39,10 +41,12 @@ let nodeQuery = require('ci-node-query')({
Return an existing query builder instance
Returns **QueryBuilder** The Query Builder object
Returns **[QueryBuilder](#querybuilder)** The Query Builder object
# QueryBuilder
**Extends QueryBuilderBase**
Main object that builds SQL queries.
**Parameters**
@ -50,17 +54,32 @@ Main object that builds SQL queries.
- `Driver` **Driver** The syntax driver for the database
- `Adapter` **Adapter** The database module adapter for running queries
## delete
## query
Run the generated delete query
Run an arbitrary sql query. Run as a prepared statement.
**Parameters**
- `sql` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The sql to execute
- `params` **\[[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)]** The query parameters
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Promise with result of query
## resetQuery
Reset the object state for a new query
Returns **void**
## truncate
Empties the selected database table
**Parameters**
- `table` **String** The table to insert into
- `where` **[Object]** Where clause for delete statement
- `callback` **[Function]** Callback for handling response from the database
- `table` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to truncate
Returns **void or Promise** If no callback is passed, a promise is returned
Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** Returns a promise if no callback is supplied
## end
@ -68,394 +87,367 @@ Closes the database connection for the current adapter
Returns **void**
## from
## select
Specify the database table to select from
Specify rows to select in the query
**Parameters**
- `tableName` **String** The table to use for the current query
- `fields` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array))** The fields to select from the current table
**Examples**
```javascript
query.from('tableName');
query.select('foo, bar'); // Select multiple fields with a string
```
```javascript
query.from('tableName t'); // Select the table with an alias
query.select(['foo', 'bar']); // Select multiple fileds with an array
```
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## get
## from
Get the results of the compiled query
Specify the database table to select from
**Parameters**
- `table` **[String]** The table to select from
- `limit` **[Number]** A limit for the query
- `offset` **[Number]** An offset for the query
- `callback` **[Function]** A callback for receiving the result
- `tableName` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to use for the current query
**Examples**
```javascript
query.get('table_name').then(promiseCallback); // Get all the rows in the table
```
```javascript
query.get('table_name', 5, callback); // Get 5 rows from the table
query.from('tableName');
```
```javascript
query.get(callback); // Get the results of a query generated with other methods
query.from('tableName t'); // Select the table with an alias
```
Returns **void or Promise** If no callback is passed, a promise is returned
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## getCompiledDelete
## like
Return generated delete query SQL
Add a 'like/ and like' clause to the query
**Parameters**
- `table` **String** the name of the table to delete from
- `reset` **[Boolean]** Whether to reset the query builder so another query can be built (optional, default `true`)
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
Returns **String** The compiled sql statement
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## getCompiledInsert
## notLike
Return generated insert query SQL
Add a 'not like/ and not like' clause to the query
**Parameters**
- `table` **String** the name of the table to insert into
- `reset` **[Boolean]** Whether to reset the query builder so another query can be built (optional, default `true`)
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
Returns **String** The compiled sql statement
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## getCompiledSelect
## orLike
Return generated select query SQL
Add an 'or like' clause to the query
**Parameters**
- `table` **[String]** the name of the table to retrieve from
- `reset` **[Boolean]** Whether to reset the query builder so another query can be built (optional, default `true`)
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
Returns **String** The compiled sql statement
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## getCompiledUpdate
## orNotLike
Return generated update query SQL
Add an 'or not like' clause to the query
**Parameters**
- `table` **String** the name of the table to update
- `reset` **[Boolean]** Whether to reset the query builder so another query can be built (optional, default `true`)
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
Returns **String** The compiled sql statement
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## groupBy
## having
Group the results by the selected field(s)
Add a 'having' clause
**Parameters**
- `field` **String or Array** The name of the field to group by
Returns **QueryBuilder** The Query Builder object, for chaining
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** The name of the field and the comparision operator, or an object
- `val` **\[([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))]** The value to compare if the value of key is a string
## groupEnd
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
Ends a logical grouping started with one of the groupStart methods
## orHaving
Returns **QueryBuilder** The Query Builder object, for chaining
Add an 'or having' clause
## groupStart
**Parameters**
Adds an open paren to the current query for logical grouping
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** The name of the field and the comparision operator, or an object
- `val` **\[([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))]** The value to compare if the value of key is a string
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## having
## where
Add a 'having' clause
Set a 'where' clause
**Parameters**
- `key` **String or Object** The name of the field and the comparision operator, or an object
- `val` **[String or Number]** The value to compare if the value of key is a string
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** The name of the field and the comparision operator, or an object
- `val` **\[([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))]** The value to compare if the value of key is a string
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## insert
## orWhere
Run the generated insert query
Set a 'or where' clause
**Parameters**
- `table` **String** The table to insert into
- `data` **[Object]** Data to insert, if not already added with the 'set' method
- `callback` **[Function]** Callback for handling response from the database
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** The name of the field and the comparision operator, or an object
- `val` **\[([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))]** The value to compare if the value of key is a string
Returns **void or Promise** If no callback is passed, a promise is returned
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## insertBatch
## whereIsNull
Insert multiple sets of rows at a time
Select a field that is Null
**Parameters**
- `table` **String** The table to insert into
- `data` **Array** The array of objects containing data rows to insert
- `callback` **[Function]** Callback for handling database response
**Examples**
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field that has a NULL value
```javascript
query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction);
```
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
```javascript
query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}])
.then(promiseCallback);
```
Returns **void or Promise** If no callback is passed, a promise is returned
## join
## whereIsNotNull
Add a join clause to the query
Specify that a field IS NOT NULL
**Parameters**
- `table` **String** The table you are joining
- `cond` **String** The join condition.
- `type` **[String]** The type of join, which defaults to inner (optional, default `'inner'`)
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name so the field that is not to be null
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## like
## orWhereIsNull
Add a 'like/ and like' clause to the query
Field is null prefixed with 'OR'
**Parameters**
- `field` **String** The name of the field to compare to
- `val` **String** The value to compare to
- `pos` **[String]** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## limit
## orWhereIsNotNull
Put a limit on the query
Field is not null prefixed with 'OR'
**Parameters**
- `limit` **Number** The maximum number of rows to fetch
- `offset` **[Number]** The row number to start from
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## notLike
## whereIn
Add a 'not like/ and not like' clause to the query
Set a 'where in' clause
**Parameters**
- `field` **String** The name of the field to compare to
- `val` **String** The value to compare to
- `pos` **[String]** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
- `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** the array of items to search in
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## orGroupStart
Adds an open paren to the current query for logical grouping,
prefixed with 'OR'
Returns **QueryBuilder** The Query Builder object, for chaining
## orHaving
## orWhereIn
Add an 'or having' clause
Set a 'or where in' clause
**Parameters**
- `key` **String or Object** The name of the field and the comparision operator, or an object
- `val` **[String or Number]** The value to compare if the value of key is a string
- `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** the array of items to search in
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## orLike
## whereNotIn
Add an 'or like' clause to the query
Set a 'where not in' clause
**Parameters**
- `field` **String** The name of the field to compare to
- `val` **String** The value to compare to
- `pos` **[String]** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
- `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** the array of items to search in
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## orNotGroupStart
## orWhereNotIn
Adds an open paren to the current query for logical grouping,
prefixed with 'OR NOT'
Set a 'or where not in' clause
Returns **QueryBuilder** The Query Builder object, for chaining
**Parameters**
## orNotLike
- `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** the array of items to search in
Add an 'or not like' clause to the query
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
**Parameters**
## set
- `field` **String** The name of the field to compare to
- `val` **String** The value to compare to
- `pos` **[String]** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
Set values for insertion or updating
Returns **QueryBuilder** The Query Builder object, for chaining
**Parameters**
## orWhere
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** The key or object to use
- `val` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The value if using a scalar key
Set a 'or where' clause
**Examples**
**Parameters**
```javascript
query.set('foo', 'bar'); // Set a key, value pair
```
- `key` **String or Object** The name of the field and the comparision operator, or an object
- `val` **[String or Number]** The value to compare if the value of key is a string
```javascript
query.set({foo:'bar'}); // Set with an object
```
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## orWhereIn
## join
Set a 'or where in' clause
Add a join clause to the query
**Parameters**
- `key` **String** the field to search
- `values` **Array** the array of items to search in
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table you are joining
- `cond` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The join condition.
- `type` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The type of join, which defaults to inner (optional, default `'inner'`)
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## orWhereIsNotNull
## groupBy
Field is not null prefixed with 'OR'
Group the results by the selected field(s)
**Parameters**
- `field` **String** The name of the field
- `field` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array))** The name of the field to group by
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## orWhereIsNull
## orderBy
Field is null prefixed with 'OR'
Order the results by the selected field(s)
**Parameters**
- `field` **String** The name of the field
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The field(s) to order by
- `type` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The order direction, ASC or DESC (optional, default `'ASC'`)
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## orWhereNotIn
## limit
Set a 'or where not in' clause
Put a limit on the query
**Parameters**
- `key` **String** the field to search
- `values` **Array** the array of items to search in
- `limit` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The maximum number of rows to fetch
- `offset` **\[[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** The row number to start from
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## orderBy
Order the results by the selected field(s)
## groupStart
**Parameters**
Adds an open paren to the current query for logical grouping
- `field` **String** The field(s) to order by
- `type` **[String]** The order direction, ASC or DESC (optional, default `'ASC'`)
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
Returns **QueryBuilder** The Query Builder object, for chaining
## orGroupStart
## query
Adds an open paren to the current query for logical grouping,
prefixed with 'OR'
Run an arbitrary sql query. Run as a prepared statement.
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
**Parameters**
## orNotGroupStart
- `sql` **string** The sql to execute
- `params` **[array]** The query parameters
- `callback` **[function]** Optional callback
Adds an open paren to the current query for logical grouping,
prefixed with 'OR NOT'
Returns **void or Promise** Returns a promise if no callback is supplied
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## resetQuery
## groupEnd
Reset the object state for a new query
Ends a logical grouping started with one of the groupStart methods
Returns **void**
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
## select
## get
Specify rows to select in the query
Get the results of the compiled query
**Parameters**
- `fields` **String or Array** The fields to select from the current table
- `table` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The table to select from
- `limit` **\[[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** A limit for the query
- `offset` **\[[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** An offset for the query
**Examples**
```javascript
query.select('foo, bar'); // Select multiple fields with a string
query.get('table_name').then(promiseCallback); // Get all the rows in the table
```
```javascript
query.select(['foo', 'bar']); // Select multiple fileds with an array
query.get('table_name', 5); // Get 5 rows from the table
```
Returns **QueryBuilder** The Query Builder object, for chaining
```javascript
query.get(); // Get the results of a query generated with other methods
```
## set
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
Set values for insertion or updating
## insert
**Parameters**
Run the generated insert query
- `key` **String or Object** The key or object to use
- `val` **[String]** The value if using a scalar key
**Parameters**
**Examples**
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** Data to insert, if not already added with the 'set' method
```javascript
query.set('foo', 'bar'); // Set a key, value pair
```
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
```javascript
query.set({foo:'bar'}); // Set with an object
```
## insertBatch
Returns **QueryBuilder** The Query Builder object, for chaining
Insert multiple sets of rows at a time
## truncate
**Parameters**
Empties the selected database table
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** The array of objects containing data rows to insert
**Parameters**
**Examples**
- `table` **string** the name of the table to truncate
- `callback` **[function]** Optional callback
```javascript
query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}])
.then(promiseCallback);
```
Returns **void or Promise** Returns a promise if no callback is supplied
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
## update
@ -463,64 +455,65 @@ Run the generated update query
**Parameters**
- `table` **String** The table to insert into
- `data` **[Object]** Data to insert, if not already added with the 'set' method
- `callback` **[Function]** Callback for handling response from the database
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** Data to insert, if not already added with the 'set' method
Returns **void or Promise** If no callback is passed, a promise is returned
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
## where
## delete
Set a 'where' clause
Run the generated delete query
**Parameters**
- `key` **String or Object** The name of the field and the comparision operator, or an object
- `val` **[String or Number]** The value to compare if the value of key is a string
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `where` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** Where clause for delete statement
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
## whereIn
## getCompiledSelect
Set a 'where in' clause
Return generated select query SQL
**Parameters**
- `key` **String** the field to search
- `values` **Array** the array of items to search in
- `table` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the name of the table to retrieve from
- `reset` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Whether to reset the query builder so another query can be built (optional, default `true`)
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
## whereIsNotNull
## getCompiledInsert
Specify that a field IS NOT NULL
Return generated insert query SQL
**Parameters**
- `field` **String** The name so the field that is not to be null
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to insert into
- `reset` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Whether to reset the query builder so another query can be built (optional, default `true`)
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
## whereIsNull
## getCompiledUpdate
Select a field that is Null
Return generated update query SQL
**Parameters**
- `field` **String** The name of the field that has a NULL value
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to update
- `reset` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Whether to reset the query builder so another query can be built (optional, default `true`)
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
## whereNotIn
## getCompiledDelete
Set a 'where not in' clause
Return generated delete query SQL
**Parameters**
- `key` **String** the field to search
- `values` **Array** the array of items to search in
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to delete from
- `reset` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Whether to reset the query builder so another query can be built (optional, default `true`)
Returns **QueryBuilder** The Query Builder object, for chaining
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
# Result
@ -528,17 +521,17 @@ Query result object
**Parameters**
- `rows` **Array** the data rows of the result
- `columns` **Array** the column names in the result
- `rows` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** the data rows of the result
- `columns` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** the column names in the result
## columnCount
## rowCount
Get the number of columns returned by the query
Get the number of rows returned by the query
Returns **Number** the number of columns in the result
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of rows in the result
## rowCount
## columnCount
Get the number of rows returned by the query
Get the number of columns returned by the query
Returns **Number** the number of rows in the result
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of columns in the result

6
CHANGELOG.md

@ -1,5 +1,9 @@
# Changelog
# 5.0.0
* Re-added firebird as a database
* Replaced all callback interfaces with promises
## 4.0.0
* Changed connection setup to just use a config object - the appropriate adapter object is created by the library.
* Removed mysql adapter, as mysql2 is very similar and does proper prepared statements
@ -11,4 +15,4 @@
* Added back tests for `node-firebird` adapter. Using this adapter with promises is not currently supported.
## 3.1.0
* Added support for promises on query execution methods
* Added support for promises on query execution methods

19
README.md

@ -9,6 +9,7 @@ A node query builder for various SQL databases, based on [CodeIgniter](http://ww
### Supported databases
* Firebird (via `node-firebird`)
* Mysql (via `mysql2`)
* PostgreSQL (via `pg`)
* Sqlite (via `dblite`)
@ -38,19 +39,9 @@ const nodeQuery = require('ci-node-query')({
// Get the query builder
const query = nodeQuery.getQuery();
query.select('foo')
.from('bar')
.where('x', 3)
.orWhere({y: 2})
.join('baz', 'baz.boo = bar.foo', 'left')
.orderBy('x', 'DESC')
.limit(2, 3)
.get(function(err, result) {
// Handle Results Here
});
// As of version 3.1.0, you can also get promises
var queryPromise = query.select('foo')
// Version 5.0.0 removes all callback interfaces
const queryPromise = query.select('foo')
.from('bar')
.where('x', 3)
.orWhere({y: 2})
@ -93,5 +84,7 @@ As of version 2, `where` and `having` type methods parse the values passed to lo
* Generated documentation is in the docs/ folder
* The API is documented in [API.md](./API.md)
* The `tests/adapters` folder contains examples of how to set up a connection for the appropriate database library
* The documentation generated for the latest dev build is also [Available](https://github.timshomepage.net/node-query/docs/)
* The documentation generated for the latest dev build is also [Available](https://github.timshomepage.net/node-query/docs/index.html)
[![js-happiness-style](https://cdn.rawgit.com/JedWatson/happiness/master/badge.svg)](https://github.com/JedWatson/happiness)

12
docs/assets/bass-addons.css

@ -0,0 +1,12 @@
.input {
font-family: inherit;
display: block;
width: 100%;
height: 2rem;
padding: .5rem;
margin-bottom: 1rem;
border: 1px solid #ccc;
font-size: .875rem;
border-radius: 3px;
box-sizing: border-box;
}

1065
docs/assets/bass.css
File diff suppressed because it is too large
View File

BIN
docs/assets/fonts/EOT/SourceCodePro-Bold.eot

BIN
docs/assets/fonts/EOT/SourceCodePro-Regular.eot

93
docs/assets/fonts/LICENSE.txt

@ -0,0 +1,93 @@
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

BIN
docs/assets/fonts/OTF/SourceCodePro-Bold.otf

BIN
docs/assets/fonts/OTF/SourceCodePro-Regular.otf

BIN
docs/assets/fonts/TTF/SourceCodePro-Bold.ttf

BIN
docs/assets/fonts/TTF/SourceCodePro-Regular.ttf

BIN
docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff

BIN
docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff

BIN
docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff

BIN
docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff

BIN
docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2

BIN
docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2

BIN
docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2

BIN
docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2

23
docs/assets/fonts/source-code-pro.css

@ -0,0 +1,23 @@
@font-face{
font-family: 'Source Code Pro';
font-weight: 400;
font-style: normal;
font-stretch: normal;
src: url('EOT/SourceCodePro-Regular.eot') format('embedded-opentype'),
url('WOFF2/TTF/SourceCodePro-Regular.ttf.woff2') format('woff2'),
url('WOFF/OTF/SourceCodePro-Regular.otf.woff') format('woff'),
url('OTF/SourceCodePro-Regular.otf') format('opentype'),
url('TTF/SourceCodePro-Regular.ttf') format('truetype');
}
@font-face{
font-family: 'Source Code Pro';
font-weight: 700;
font-style: normal;
font-stretch: normal;
src: url('EOT/SourceCodePro-Bold.eot') format('embedded-opentype'),
url('WOFF2/TTF/SourceCodePro-Bold.ttf.woff2') format('woff2'),
url('WOFF/OTF/SourceCodePro-Bold.otf.woff') format('woff'),
url('OTF/SourceCodePro-Bold.otf') format('opentype'),
url('TTF/SourceCodePro-Bold.ttf') format('truetype');
}

110
docs/assets/site.js

@ -2,39 +2,107 @@
// add anchor links to headers
anchors.options.placement = 'left';
anchors.add().remove('.no-anchor');
anchors.add('h3');
// Filter UI
var tocElements = document.getElementById('toc').getElementsByTagName('a');
document.getElementById('filter-input').addEventListener('keyup', function(e) {
var tocElements = document.getElementById('toc')
.getElementsByTagName('li');
var i, element;
document.getElementById('filter-input')
.addEventListener('keyup', function (e) {
var i, element, children;
// enter key
if (e.keyCode === 13) {
// go to the first displayed item in the toc
for (i = 0; i < tocElements.length; i++) {
element = tocElements[i];
if (!element.classList.contains('display-none')) {
location.replace(element.firstChild.href);
return e.preventDefault();
}
}
}
var match = function () {
return true;
};
var value = this.value.toLowerCase();
if (!value.match(/^\s*$/)) {
match = function (element) {
return element.firstChild.innerHTML.toLowerCase().indexOf(value) !== -1;
};
}
// enter key
if (e.keyCode === 13) {
// go to the first displayed item in the toc
for (i = 0; i < tocElements.length; i++) {
element = tocElements[i];
if (!element.classList.contains('hide')) {
location.replace(element.href);
return e.preventDefault();
children = Array.from(element.getElementsByTagName('li'));
if (match(element) || children.some(match)) {
element.classList.remove('display-none');
} else {
element.classList.add('display-none');
}
}
});
var toggles = document.getElementsByClassName('toggle-step-sibling');
for (var i = 0; i < toggles.length; i++) {
toggles[i].addEventListener('click', toggleStepSibling);
}
function toggleStepSibling() {
var stepSibling = this.parentNode.parentNode.parentNode.getElementsByClassName('toggle-target')[0];
var klass = 'display-none';
if (stepSibling.classList.contains(klass)) {
stepSibling.classList.remove(klass);
stepSibling.innerHTML = '▾';
} else {
stepSibling.classList.add(klass);
stepSibling.innerHTML = '▸';
}
}
var match = function() { return true; },
value = this.value.toLowerCase();
var items = document.getElementsByClassName('toggle-sibling');
for (var j = 0; j < items.length; j++) {
items[j].addEventListener('click', toggleSibling);
}
if (!value.match(/^\s*$/)) {
match = function(text) { return text.toLowerCase().indexOf(value) !== -1; };
function toggleSibling() {
var stepSibling = this.parentNode.getElementsByClassName('toggle-target')[0];
var icon = this.getElementsByClassName('icon')[0];
var klass = 'display-none';
if (stepSibling.classList.contains(klass)) {
stepSibling.classList.remove(klass);
icon.innerHTML = '▾';
} else {
stepSibling.classList.add(klass);
icon.innerHTML = '▸';
}
}
for (i = 0; i < tocElements.length; i++) {
element = tocElements[i];
if (match(element.innerHTML)) {
element.classList.remove('hide');
} else {
element.classList.add('hide');
}
function showHashTarget(targetId) {
var hashTarget = document.getElementById(targetId);
// new target is hidden
if (hashTarget && hashTarget.offsetHeight === 0 &&
hashTarget.parentNode.parentNode.classList.contains('display-none')) {
hashTarget.parentNode.parentNode.classList.remove('display-none');
}
}
window.addEventListener('hashchange', function() {
showHashTarget(location.hash.substring(1));
});
showHashTarget(location.hash.substring(1));
var toclinks = document.getElementsByClassName('pre-open');
for (var k = 0; k < toclinks.length; k++) {
toclinks[k].addEventListener('mousedown', preOpen, false);
}
function preOpen() {
showHashTarget(this.hash.substring(1));
}

135
docs/assets/style.css

@ -1,66 +1,53 @@
.documentation a {
color: #1184CE;
}
.documentation .suppress-p-margin p {
margin:0;
.documentation {
font-family: Helvetica, sans-serif;
color: #666;
line-height: 1.5;
background: #f5f5f5;
}
.force-inline, .force-inline p {
display: inline;
color: #222;
.black {
color: #666;
}
.container-small {
max-width: 58rem;
margin-left: auto;
margin-right: auto;
.bg-white {
background-color: #fff;
}
.max-height-100 {
max-height: 100%;
h4 {
margin: 20px 0 10px 0;
}
.fade {
opacity:0.50;
.documentation h3 {
color: #000;
}
.button-indent {
padding: .25rem 1.5rem;
font-size: 90%;
.border-bottom {
border-color: #ddd;
}
.section-indent {
border-left: 2px solid #eee;
a {
color: #1184CE;
text-decoration: none;
}
.bg-cloudy {
background: #fafafa;
.documentation a[href]:hover {
text-decoration: underline;
}
.force-inline * {
display:inline;
a:hover {
cursor: pointer;
}
section:target h3 {
font-weight:700;
.py1-ul li {
padding: 5px 0;
}
.documentation,
.documentation h1,
.documentation h2,
.documentation h3,
.documentation h4,
.documentation h5,
.documentation h6 {
font-family: 'Source Sans Pro', Helvetica, sans-serif;
.max-height-100 {
max-height: 100%;
}
.documentation pre,
.documentation code,
.documentation samp {
font-family: 'Source Code Pro', monospace;
font-size: 90%;
section:target h3 {
font-weight:700;
}
.documentation td,
@ -75,12 +62,9 @@ h4:hover .anchorjs-link {
opacity: 1;
}
.collapsible .collapser {
display:none;
}
.collapsible:target .collapser {
display: block;
.fix-3 {
width: 25%;
max-width: 244px;
}
.fix-3 {
@ -93,3 +77,60 @@ h4:hover .anchorjs-link {
margin-left: 25%;
}
}
.pre, pre, code, .code {
font-family: Source Code Pro,Menlo,Consolas,Liberation Mono,monospace;
font-size: 14px;
}
.fill-light {
background: #F9F9F9;
}
.width2 {
width: 1rem;
}
.input {
font-family: inherit;
display: block;
width: 100%;
height: 2rem;
padding: .5rem;
margin-bottom: 1rem;
border: 1px solid #ccc;
font-size: .875rem;
border-radius: 3px;
box-sizing: border-box;
}
table {
border-collapse: collapse;
}
.prose table th,
.prose table td {
text-align: left;
padding:8px;
border:1px solid #ddd;
}
.prose table th:nth-child(1) { border-right: none; }
.prose table th:nth-child(2) { border-left: none; }
.prose table {
border:1px solid #ddd;
}
.prose-big {
font-size: 18px;
line-height: 30px;
}
.quiet {
opacity: 0.7;
}
.minishadow {
box-shadow: 2px 2px 10px #f3f3f3;
}

5792
docs/index.html
File diff suppressed because it is too large
View File

87
gulpfile.js

@ -1,87 +0,0 @@
'use strict';
const documentation = require('gulp-documentation'),
eslint = require('gulp-eslint'),
gulp = require('gulp'),
istanbul = require('gulp-istanbul'),
jscs = require('gulp-jscs'),
mocha = require('gulp-mocha'),
pipe = require('gulp-pipe'),
sloc = require('gulp-sloc');
const SRC_FILES = ['lib/**/*.js'];
const TEST_FILES = [
'test/*_test.js',
'test/adapters/*_test.js'
];
const MOCHA_OPTIONS = {
ui: 'tdd',
bail: true,
reporter: 'dot',
timeout: 10000,
};
gulp.task('lint', () => {
pipe(gulp.src(SRC_FILES), [
eslint(),
eslint.format(),
eslint.failAfterError()
]);
pipe(gulp.src(SRC_FILES), [
jscs(),
jscs.reporter()
]);
});
gulp.task('lint-tests', ['lint'], () => {
pipe(gulp.src(['test/**/*.js']), [
eslint(),
eslint.format(),
eslint.failAfterError()
]);
pipe(gulp.src(['test/**/*.js']), [
jscs(),
jscs.reporter()
]);
});
gulp.task('sloc', () => gulp.src(SRC_FILES).pipe(sloc()));
gulp.task('test-sloc', () => gulp.src(TEST_FILES).pipe(sloc()));
gulp.task('docs', () => {
gulp.src(['lib/*.js'])
.pipe(documentation({format: 'html'}))
.pipe(gulp.dest('docs'));
gulp.src(['lib/*.js'])
.pipe(documentation({format: 'md'}))
.pipe(gulp.dest('.'));
});
gulp.task('mocha', ['lint-tests', 'sloc'], () => {
return gulp.src(TEST_FILES)
.pipe(mocha(MOCHA_OPTIONS))
.once('error', () => {
process.exit(1);
})
.once('end', () => {
process.exit();
});
});
gulp.task('test', ['test-sloc', 'lint-tests'], function(cb) {
return pipe(gulp.src(SRC_FILES), [
istanbul(),
istanbul.hookRequire()
]).on('finish', () => {
pipe(gulp.src(TEST_FILES), [
mocha(MOCHA_OPTIONS),
istanbul.writeReports({
dir: './coverage',
reporters: ['clover', 'lcov', 'lcovonly', 'html', 'text'],
}),
]);
});
});
gulp.task('default', ['lint', 'sloc', 'docs', 'test']);

20
lib/Adapter.js

@ -1,20 +1,19 @@
'use strict';
/**
* Class that wraps database connection libraries
*
* @private
* @param {Object} instance - The connection object
* @param {Promise} instance - The connection object
*/
class Adapter {
/**
* Invoke an adapter
*
* @constructor
* @param {Object} instance - The connection object
* @param {Promise} instance - Promise holding connection object
*/
constructor(instance) {
constructor (instance) {
this.instance = instance;
}
@ -23,10 +22,9 @@ class Adapter {
*
* @param {String} sql - The sql with placeholders
* @param {Array} params - The values to insert into the query
* @param {Function} [callback] - Callback to run when a response is recieved
* @return {void|Promise} - returns a promise if no callback is passed
* @return {Promise} - returns a promise if no callback is passed
*/
execute(/*sql, params, callback*/) {
execute (sql, params) {
throw new Error('Correct adapter not defined for query execution');
}
@ -36,7 +34,7 @@ class Adapter {
* @param {*} originalResult - the original result object from the driver
* @return {Result} - the new result object
*/
transformResult(originalResult) {
transformResult (originalResult) {
throw new Error('Result transformer method not defined for current adapter');
}
@ -44,9 +42,9 @@ class Adapter {
* Close the current database connection
* @return {void}
*/
close() {
this.instance.end();
close () {
this.instance.then(conn => conn.end());
}
}
module.exports = Adapter;
module.exports = Adapter;

65
lib/Driver.js

@ -7,7 +7,7 @@ const helpers = require('./helpers');
*
* @private
*/
let Driver = {
const Driver = {
identifierStartChar: '"',
identifierEndChar: '"',
tablePrefix: null,
@ -20,9 +20,9 @@ let Driver = {
* @return {String} - The quoted sql fragment
* @private
*/
_quote(str) {
return (helpers.isString(str)
&& ! (str.startsWith(Driver.identifierStartChar) || str.endsWith(Driver.identifierEndChar))
_quote (str) {
return (helpers.isString(str) &&
!(str.startsWith(Driver.identifierStartChar) || str.endsWith(Driver.identifierEndChar))
)
? `${Driver.identifierStartChar}${str}${Driver.identifierEndChar}`
: str;
@ -30,17 +30,16 @@ let Driver = {
/**
* Set the limit clause
* @private
* @param {String} sql - SQL statement to modify
* @param {Number} limit - Maximum number of rows to fetch
* @param {Number} [offset] - Number of rows to skip
* @return {String} - Modified SQL statement
*/
limit(sql, limit, offset) {
sql += ` LIMIT ${limit}`;
limit (sql, limit, offset) {
sql += ` LIMIT ${limit}`;
if (helpers.isNumber(offset))
{
if (helpers.isNumber(offset)) {
sql += ` OFFSET ${offset}`;
}
@ -50,10 +49,11 @@ let Driver = {
/**
* Quote database table name, and set prefix
*
* @private
* @param {String} table - Table name to quote
* @return {String} - Quoted table name
*/
quoteTable(table) {
quoteTable (table) {
// Quote after prefix
return Driver.quoteIdentifiers(table);
},
@ -61,25 +61,24 @@ let Driver = {
/**
* Use the driver's escape character to quote identifiers
*
* @private
* @param {String|Array} str - String or array of strings to quote identifiers
* @return {String|Array} - Quoted identifier(s)
*/
quoteIdentifiers(str) {
quoteIdentifiers (str) {
let hiers, raw;
let pattern = new RegExp(
`${Driver.identifierStartChar}(`
+ '([a-zA-Z0-9_]+)' + '(\((.*?)\))'
+ `)${Driver.identifierEndChar}`, 'ig');
`${Driver.identifierStartChar}(` +
'([a-zA-Z0-9_]+)' + '(((.*?)))' +
`)${Driver.identifierEndChar}`, 'ig');
// Recurse for arrays of identifiiers
if (Array.isArray(str))
{
if (Array.isArray(str)) {
return str.map(Driver.quoteIdentifiers);
}