knex: type knex.fn helper (#11422)

As stated in sources, knex.fn contains only one function, `now()`, which returns `Raw`. As stated in documentation, `Raw` could be used as any value in query builder, so, this commit includes 2 changes:
1. Add `Raw` as one of case for type `Value`;
2. Introduce `FunctionHelper` interface (as in original source), which is returned by `knex.fn`.

https://github.com/tgriesser/knex/blob/master/src/functionhelper.js
http://knexjs.org/#Schema-timestamp (see Example section)
This commit is contained in:
Artur Eshenbrener
2016-09-23 16:41:17 +04:00
committed by Masahiro Wakame
parent 964424bd7e
commit 1bd8a1e366
2 changed files with 7 additions and 2 deletions

View File

@@ -421,6 +421,7 @@ knex.schema.createTable('users', function (table) {
table.string('name');
table.enu('favorite_color', ['red', 'blue', 'green']);
table.timestamps();
table.timestamp('created_at').defaultTo(knex.fn.now());
});
knex.schema.renameTable('users', 'old_users');

8
knex/knex.d.ts vendored
View File

@@ -12,7 +12,7 @@ declare module "knex" {
type Callback = Function;
type Client = Function;
type Value = string|number|boolean|Date|Array<string>|Array<number>|Array<Date>|Array<boolean>|Buffer;
type Value = string|number|boolean|Date|Array<string>|Array<number>|Array<Date>|Array<boolean>|Buffer|Knex.Raw;
type ColumnName = string|Knex.Raw|Knex.QueryBuilder;
type TableName = string|Knex.Raw|Knex.QueryBuilder;
@@ -31,7 +31,7 @@ declare module "knex" {
client: any;
migrate: Knex.Migrator;
seed: any;
fn: any;
fn: Knex.FunctionHelper;
on(eventName: string, callback: Function): Knex.QueryBuilder;
}
@@ -546,6 +546,10 @@ declare module "knex" {
status(config?: MigratorConfig):Promise<number>;
currentVersion(config?: MigratorConfig):Promise<string>;
}
interface FunctionHelper {
now(): Raw;
}
}
export = Knex;