Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

any-db-adapter-spec

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

any-db-adapter-spec - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

63

interfaces/queryable.js

@@ -0,1 +1,2 @@

var inOrder = require('assert-in-order')
var EventEmitter = require('events').EventEmitter

@@ -28,52 +29,44 @@

function testEventsWithResults (queryable, test, name) {
test.plan(19)
var emittedFields = false
, emittedData = false
, emittedClose = false
, emittedEnd = false
, callbackCalled = false
var query = queryable.adapter.createQuery('SELECT 1 AS val', function (err, result) {
test.ok(!callbackCalled, 'callback was not already called')
if (err) throw err
callbackCalled = true
test.ok(emittedFields, 'callback after query.emit("fields", fields)')
test.ok(emittedData, 'callback after query.emit("data", row)')
test.ok(emittedClose, 'callback after query.emit("close")')
test.ok(!emittedEnd, 'callback before query.emit("end")')
var rows = [{val: 1}]
var expectations = inOrder(test, {
'query.callback': ['equal', callback, 'query.callback === callback'],
queryEquals: ['equal', 'query is identical'],
fields: ['pass', 'query.emit("fields")'],
rowEquals: ['deepEqual', rows[0], 'got correct row in "data" event'],
noCloseArgs: ['equal', 0, 'No extra arguments to "close" event'],
rowsEqual: ['deepEqual', rows, 'got correct rows in callback'],
noEndArgs: ['equal', 0, 'No extra arguments to "end" event'],
})
test.plan(Object.keys(expectations).length)
var query = queryable.adapter.createQuery('SELECT 1 AS val', callback)
expectations['query.callback'](query.callback)
queryable.once('query', function (q) {
test.equal(q, query, name + '.emit("query", query)')
expectations.queryEquals(q, query)
})
query.on('fields', function (fields) {
emittedFields = true
test.ok(Array.isArray(fields), '"fields" event value is an array')
query.on('fields', function () {
expectations.fields()
})
query.on('data', function (row) {
emittedData = true
test.ok(emittedFields, 'query.emit("data") after query.emit("fields")')
test.equal(row.val, 1)
expectations.rowEquals(row)
})
query.on('close', function (arg) {
test.ok(!emittedClose, 'query.emit("close") emitted once')
emittedClose = true
test.ok(emittedFields, 'query.emit("close") after query.emit("fields")')
test.ok(emittedData, 'query.emit("close") after query.emit("data")')
test.ok(!arg, 'No extra arguments to "end" event')
query.on('close', function () {
expectations.noCloseArgs(arguments.length)
})
query.on('end', function (arg) {
test.ok(!emittedEnd, 'query.emit("end") emitted once')
emittedEnd = true
test.ok(emittedClose, 'query.emit("end") after query.emit("close")')
test.ok(emittedFields, 'query.emit("end") after query.emit("fields")')
test.ok(emittedData, 'query.emit("end") after query.emit("data")')
test.ok(!arg, 'No extra arguments to "end" event')
query.on('end', function () {
expectations.noEndArgs(arguments.length)
})
test.equal(queryable.query(query), query, name + '.query(query) returns same query')
function callback (err, result) {
if (err) throw err
expectations.rowsEqual(result.rows)
}
}

@@ -80,0 +73,0 @@

{
"name": "any-db-adapter-spec",
"version": "2.1.0",
"version": "2.1.1",
"description": "Specification and test suite for any-db adapters",

@@ -27,3 +27,4 @@ "main": "test-any-db-adapter.js",

"tape": "~2.3.2",
"parse-db-url": "0.0.0"
"parse-db-url": "0.0.0",
"assert-in-order": "0.0.3"
},

@@ -30,0 +31,0 @@ "devDependencies": {},

@@ -120,3 +120,4 @@ # Any-DB API

text: String,
values: Array
values: Array,
callback: null | (Error, Results) => void
}

@@ -146,2 +147,9 @@ ```

### Query.callback
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`
property of a `Query` they did not create.
### Query Events

@@ -148,0 +156,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc