Skip to content

Commit

Permalink
Prettier everything
Browse files Browse the repository at this point in the history
  • Loading branch information
grncdr committed Jul 14, 2018
1 parent bbc83a9 commit 9608fde
Show file tree
Hide file tree
Showing 67 changed files with 963 additions and 886 deletions.
4 changes: 4 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
semi: false
singleQuote: true
trailingComma: all
printWidth: 100
99 changes: 51 additions & 48 deletions packages/any-db-adapter-spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ implement.

## Interfaces

- [Queryable][] - a common interface implemented by connections, pools, and
transactions.
- [Connection][] - the "transport" responsible for getting SQL queries to a
database, and streaming results back through a `Query` instance.
- [Query][] - a [Readable][] stream that emits row objects.
- [Queryable][] - a common interface implemented by connections, pools, and
transactions.
- [Connection][] - the "transport" responsible for getting SQL queries to a
database, and streaming results back through a `Query` instance.
- [Query][] - a [Readable][] stream that emits row objects.

## Callbacks

Expand All @@ -38,9 +38,10 @@ Queryable := EventEmitter & {
```

Known implementations:
- [Connection][Connection]
- [ConnectionPool][ConnectionPool] (external)
- [Transaction][Transaction] (external).

- [Connection][connection]
- [ConnectionPool][connectionpool] (external)
- [Transaction][transaction] (external).

### Queryable.adapter

Expand All @@ -64,21 +65,26 @@ The second form is not needed for normal use, but must be implemented by
adapters to work correctly with [ConnectionPool][] and [Transaction][]. See
[Adapter.createQuery](#adapter-createquery) for more details.

*Callback-style*
_Callback-style_

```javascript
queryable.query('SELECT * FROM my_table', function (err, res) {
queryable.query('SELECT * FROM my_table', function(err, res) {
if (err) return console.error(err)
res.rows.forEach(console.log)
console.log('All done!')
})
```

*Stream-style*
_Stream-style_

```javascript
queryable.query('SELECT * FROM my_table')
queryable
.query('SELECT * FROM my_table')
.on('error', console.error)
.on('data', console.log)
.on('end', function () { console.log('All done!') })
.on('end', function() {
console.log('All done!')
})
```

### Queryable events
Expand All @@ -89,7 +95,7 @@ The `'query'` event is emitted immediately before a query is executed.

One argument is passed to event handlers:

* `query` - a [Query][] object
- `query` - a [Query][] object

## Connection

Expand All @@ -101,9 +107,9 @@ Connection := Queryable & {

Known implementations:

- [any-db-mysql][] (external)
- [any-db-postgres][] (external)
- [any-db-sqlite3][] (external)
- [any-db-mysql][] (external)
- [any-db-postgres][] (external)
- [any-db-sqlite3][] (external)

Connection objects are obtained using [createConnection][] from [Any-DB][] or
[ConnectionPool.acquire][], both of which delegate to the
Expand Down Expand Up @@ -154,32 +160,32 @@ Query := Readable<Object> & {
}
```

`Query` objects are returned by the [Queryable.query][Queryable.query] method,
available on [connections][Connection], [pools][ConnectionPool.query], and
[transactions][Transaction.query]. Queries are instances of [Readable][], and
as such can be [piped][Readable.pipe] through transforms and support backpressure
`Query` objects are returned by the [Queryable.query][queryable.query] method,
available on [connections][connection], [pools][connectionpool.query], and
[transactions][transaction.query]. Queries are instances of [Readable][], and
as such can be [piped][readable.pipe] through transforms and support backpressure
for more efficient memory-usage on very large results sets. (Note: at this time
the `sqlite3` driver does not support backpressure)

Internally, `Query` instances are
[created by a database Adapter][Adapter.createQuery] and may have more methods,
[created by a database Adapter][adapter.createquery] and may have more methods,
properties, and events than are described here. Consult the documentation for
your specific adapter to find out about any extensions.

### Query.text

The SQL query as a string. If you are using MySQL this will contain
interpolated values *after* the query has been enqueued by a connection.
interpolated values _after_ the query has been enqueued by a connection.

### Query.values

The array of parameter values.

### Query.callback

The callback (if any) that was provided to [Queryable.query][Queryable.query].
The callback (if any) that was provided to [Queryable.query][queryable.query].
Note that `Query` objects **must not** use a closed over reference to their
callback, as other `any-db` libraries *may* rely on modifying the `callback`
callback, as other `any-db` libraries _may_ rely on modifying the `callback`
property of a `Query` they did not create.

### Query Events
Expand All @@ -192,15 +198,15 @@ be subscribed to the `'error'` event.

One argument is passed to event listeners:

* `error` - the error object.
- `error` - the error object.

#### Fields event

A `'fields'` event is emmitted before any `'data'` events.

One argument is passed to event listeners:

* `fields` - an array of [Field][ResultSet] objects.
- `fields` - an array of [Field][resultset] objects.

### [Readable][] events

Expand All @@ -212,7 +218,7 @@ A `'data'` event is emitted for each row in the query result set.

One argument is passed to event listeners:

* `row` contains the contents of a single row in the query result
- `row` contains the contents of a single row in the query result

#### Close event

Expand Down Expand Up @@ -242,7 +248,7 @@ Field := {
}
```

`ResultSet` objects are just plain data that collect results of a query when a
`ResultSet` objects are just plain data that collect results of a query when a
continuation is provided to [Queryable.query][]. The `lastInsertId` is optional,
and currently supported by `sqlite3` and `mysql` but not `postgres`, because
it is not supported by Postgres itself.
Expand Down Expand Up @@ -283,7 +289,7 @@ See also: the [Connection API](#connection)
(Query) => Query {* returns same Query *}
```

Create a [Query](#query) that *may* eventually be executed later on by a
Create a [Query](#query) that _may_ eventually be executed later on by a
[Connection][]. While this function is rarely needed by user code, it makes
it possible for [ConnectionPool.query][] and [Transaction.query][] to fulfill
the [Queryable.query][] contract by synchronously returning a [Query][] stream.
Expand All @@ -299,23 +305,20 @@ the [Queryable.query][] contract by synchronously returning a [Query][] stream.
[any-db-mysql]: https://github.com/grncdr/node-any-db-mysql
[any-db-postgres]: https://github.com/grncdr/node-any-db-postgres
[any-db-sqlite3]: https://github.com/grncdr/node-any-db-sqlite3
[createConnection]: https://github.com/grncdr/node-any-db#exportscreateconnection

[Readable]: http://nodejs.org/api/stream.html#stream_class_stream_readable
[Readable.pipe]: http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options

[ConnectionPool.query]: https://github.com/grncdr/node-any-db-pool#connectionpoolquery
[ConnectionPool.acquire]: https://github.com/grncdr/node-any-db-pool#connectionpoolacquire
[ConnectionPool]: https://github.com/grncdr/node-any-db-pool#api
[Transaction]: https://github.com/grncdr/node-any-db-transaction#api
[createconnection]: https://github.com/grncdr/node-any-db#exportscreateconnection
[readable]: http://nodejs.org/api/stream.html#stream_class_stream_readable
[readable.pipe]: http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
[connectionpool.query]: https://github.com/grncdr/node-any-db-pool#connectionpoolquery
[connectionpool.acquire]: https://github.com/grncdr/node-any-db-pool#connectionpoolacquire
[connectionpool]: https://github.com/grncdr/node-any-db-pool#api
[transaction]: https://github.com/grncdr/node-any-db-transaction#api
[any-db-transaction]: https://github.com/grncdr/node-any-db-transaction
[Transaction.query]: https://github.com/grncdr/node-any-db-transaction#transactionquery

[transaction.query]: https://github.com/grncdr/node-any-db-transaction#transactionquery
[test suite]: tests
[Adapter]: #adapter
[Queryable]: #queryable
[Queryable.query]: #queryablequery
[Connection]: #connection
[Connection.query]: #connectionquery
[Query]: #query
[Adapter.createQuery]: #adaptercreatequery
[adapter]: #adapter
[queryable]: #queryable
[queryable.query]: #queryablequery
[connection]: #connection
[connection.query]: #connectionquery
[query]: #query
[adapter.createquery]: #adaptercreatequery
4 changes: 1 addition & 3 deletions packages/any-db-adapter-spec/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ var cc = require('config-chain')
var argv = require('optimist').argv
var parseDbUrl = require('parse-db-url')

var config = cc(camelize(argv),
camelize(cc.env('any_db_test_')),
{ adapterPath: process.cwd() })
var config = cc(camelize(argv), camelize(cc.env('any_db_test_')), { adapterPath: process.cwd() })

var adapterPath = path.resolve(config.get('adapterPath'))
config.set('adapterPath', adapterPath)
Expand Down
9 changes: 6 additions & 3 deletions packages/any-db-adapter-spec/interfaces/adapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

exports.testProperties = function (adapter, assert) {
exports.testProperties = function(adapter, assert) {
assert.equal(typeof adapter.name, 'string', 'adapter.name is a string')
assert.equal(typeof adapter.createConnection, 'function', 'adapter.createConnection is a function')
assert.equal(
typeof adapter.createConnection,
'function',
'adapter.createConnection is a function',
)
assert.equal(typeof adapter.createQuery, 'function', 'adapter.createQuery is a function')
}
6 changes: 3 additions & 3 deletions packages/any-db-adapter-spec/interfaces/connection.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var Queryable = require('./queryable')

exports.testProperties = function (connection, adapter, assert) {
exports.testProperties = function(connection, adapter, assert) {
Queryable.testProperties(connection, adapter, assert, 'connection')
assert.equal(typeof connection.end, 'function')
}

exports.testEvents = function (connection, assert) {
connection.on('open', function () {
exports.testEvents = function(connection, assert) {
connection.on('open', function() {
assert.ok(1, 'connection.emit("open")')
Queryable.testEvents(connection, assert, 'connection')
})
Expand Down
8 changes: 4 additions & 4 deletions packages/any-db-adapter-spec/interfaces/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports.Adapter = require('./adapter')
exports.Query = require('./query')
exports.Queryable = require('./queryable')
exports.Adapter = require('./adapter')
exports.Query = require('./query')
exports.Queryable = require('./queryable')
exports.Connection = require('./connection')
exports.ResultSet = require('./result-set')
exports.ResultSet = require('./result-set')
14 changes: 7 additions & 7 deletions packages/any-db-adapter-spec/interfaces/query.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var EventEmitter = require('events').EventEmitter

exports.testProperties = function (query, assert) {
assert.ok(query instanceof EventEmitter, "query is an EventEmitter")
assert.equal(typeof query.text, 'string', 'query.text is a string')
assert.equal(typeof query.values, 'object', 'query.values is an object')
assert.equal(typeof query.pause, 'function', 'query.pause is a function')
exports.testProperties = function(query, assert) {
assert.ok(query instanceof EventEmitter, 'query is an EventEmitter')
assert.equal(typeof query.text, 'string', 'query.text is a string')
assert.equal(typeof query.values, 'object', 'query.values is an object')
assert.equal(typeof query.pause, 'function', 'query.pause is a function')
assert.equal(typeof query.resume, 'function', 'query.resume is a function')
if (query.callback) assert.equal(typeof query.callback, 'function',
'query.callback is a function')
if (query.callback)
assert.equal(typeof query.callback, 'function', 'query.callback is a function')
}
Loading

0 comments on commit 9608fde

Please sign in to comment.