Comparing version 1.2.1 to 1.3.0
{ | ||
"name": "knexed", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
@@ -34,3 +34,3 @@ "description": "Knex utilities", | ||
"st": "eslint *.js tx/ table/ query/ test/", | ||
"flow": "flow check", | ||
"t": "glow || flow", | ||
@@ -40,3 +40,3 @@ "mocha": "mocha --check-leaks --recursive test/**.test.js test/**/*.test.js", | ||
"test": "npm run st && npm run flow && npm run mocha", | ||
"test": "npm run st && npm run t && npm run mocha", | ||
"all": "npm test && npm run cover", | ||
@@ -50,3 +50,3 @@ | ||
"knex": | ||
"0.13", | ||
"0.14", | ||
@@ -60,3 +60,3 @@ "mocha": | ||
"sqlite3": | ||
"3", | ||
"4", | ||
@@ -73,3 +73,3 @@ "lodash": | ||
"flow-bin": | ||
"0.61", | ||
"0.73", | ||
@@ -80,4 +80,4 @@ "eslint": | ||
"js-outlander": | ||
"StrangeTransistor/js-outlander#2.3.0" | ||
"StrangeTransistor/js-outlander#2.3.1" | ||
} | ||
} |
/* @flow */ | ||
/* :: | ||
module.exports = function count (query /* :Knex$Query */) | ||
import type { $QueryBuilder } from 'knex' | ||
*/ | ||
module.exports = function count (query /* :$QueryBuilder<any> */) | ||
/* :Promise<number> */ | ||
@@ -5,0 +10,0 @@ { |
/* @flow */ | ||
/* :: | ||
module.exports = function exists (query /* :Knex$Query */) | ||
import type { $QueryBuilder } from 'knex' | ||
*/ | ||
module.exports = function exists (query /* :$QueryBuilder<any> */) | ||
/* :Promise<boolean> */ | ||
@@ -5,0 +10,0 @@ { |
/* @flow */ | ||
/* :: | ||
import type { TableFn, Table } from '../table/table'; | ||
type Join = TableFn; | ||
import type { TableFn, Table } from '../table/table' | ||
import type { Knex$Transaction$Optional } from '../tx/method' | ||
type TableRef | ||
= Alias | ||
| Table | ||
; | ||
type Join = TableFn | ||
type Alias = [ Table, string ]; | ||
type TableRef | ||
= Alias | ||
| Table | ||
export type Predicate | ||
= [ string, Operator, string ] | ||
| [ string, string ] | ||
| string | ||
; | ||
type Alias = [ Table, string ] | ||
type Operator | ||
= '=' | ||
| '>' | ||
| '<' | ||
| '>=' | ||
| '<=' | ||
| '<>' | ||
| '!=' | ||
; | ||
export type Predicate | ||
= [ string, Operator, string ] | ||
| [ string, string ] | ||
| string | ||
type Operator | ||
= '=' | ||
| '>' | ||
| '<' | ||
| '>=' | ||
| '<=' | ||
| '<>' | ||
| '!=' | ||
*/ | ||
@@ -56,3 +56,3 @@ | ||
return (tx /* :Knex$Transaction$Optional */) => | ||
return (tx /* :Knex$Transaction$Optional<any> */) => | ||
{ | ||
@@ -78,3 +78,3 @@ return tableL | ||
return (tx /* :Knex$Transaction$Optional */) => | ||
return (tx /* :Knex$Transaction$Optional<any> */) => | ||
{ | ||
@@ -81,0 +81,0 @@ return tableL |
/* @flow */ | ||
/* :: | ||
export type TableFn = (tx :Knex$Transaction$Optional) => Knex$Query; | ||
export type Table | ||
= TableFn | ||
& | ||
{ | ||
as: (alias :?string, tx :Knex$Transaction$Optional) => Knex$Query, | ||
import type { Knex } from 'knex' | ||
import type { $QueryBuilder } from 'knex' | ||
relname: (alias :?string) => string, | ||
+toString: () => string, | ||
import type { Knex$Transaction$Optional } from '../tx/method' | ||
kx: Knex, | ||
}; | ||
export type TableFn = (tx :Knex$Transaction$Optional<any>) | ||
=> $QueryBuilder<any>; | ||
export type Table | ||
= TableFn | ||
& | ||
{ | ||
as(alias :?string, tx :Knex$Transaction$Optional<any>): $QueryBuilder<any>, | ||
relname(alias :?string): string, | ||
toString(): string, | ||
kx: Knex, | ||
} | ||
*/ | ||
// TODO: generic | ||
module.exports = function table (kx /* :Knex */, table_name /* :string */) | ||
/* :Table */ | ||
{ | ||
var t = (tx /* :Knex$Transaction$Optional */) => | ||
var t = (tx /* :Knex$Transaction$Optional<any> */) => | ||
{ | ||
@@ -28,3 +37,3 @@ return transacted(kx, table_name, tx) | ||
t.as = (alias /* :?string */, tx /* :Knex$Transaction$Optional */) => | ||
t.as = (alias /* :?string */, tx /* :Knex$Transaction$Optional<any> */) => | ||
{ | ||
@@ -56,2 +65,6 @@ return transacted(kx, relname(alias), tx) | ||
var NOTX = require('../tx/method').NOTX | ||
// TODO: generic | ||
function transacted | ||
@@ -61,8 +74,21 @@ ( | ||
table_name /* :string */, | ||
tx /* :Knex$Transaction$Optional */ | ||
tx /* :Knex$Transaction$Optional<any> */ | ||
) | ||
/* :Knex$Query */ | ||
/* :$QueryBuilder<any> */ | ||
{ | ||
return kx(table_name) | ||
.transacting(tx) | ||
var q = kx(table_name) | ||
if (! tx) | ||
{ | ||
return q | ||
} | ||
if (tx === NOTX) | ||
{ | ||
return q | ||
} | ||
/* @flow-off */ | ||
/* :: tx = (tx :Knex$Transaction$Optional<any>) */ | ||
return q.transacting(tx) | ||
} |
/* @flow */ | ||
/* :: | ||
type RetPromise<T> | ||
= ( ...args: Array<any>) => Promise<T> | ||
type TxRetPromise<T> | ||
= (tx: Knex$Transaction, ...args: Array<any>) => Promise<T> | ||
import type { Knex } from 'knex' | ||
export type Knex$Transaction$Optional<T> | ||
= Knex$Transaction<T> | ||
| void | ||
| null | ||
| Symbol // NOTX | ||
export type RetPromise<T> | ||
= ( ...args: Array<any>) => Promise<T> | ||
export type TxRetPromise<T> | ||
= (tx: Knex$Transaction<T>, ...args: Array<any>) => Promise<T> | ||
*/ | ||
@@ -25,3 +35,3 @@ | ||
( | ||
tx /* :Knex$Transaction$Optional */ | ||
tx /* :Knex$Transaction$Optional<T> */ | ||
/* ::, ...args: Array<any> */ | ||
@@ -28,0 +38,0 @@ ) |
25134
640