From 1bd8a1e36603d8c021c54f7ac3e8935e9a2cdc45 Mon Sep 17 00:00:00 2001 From: Artur Eshenbrener Date: Fri, 23 Sep 2016 16:41:17 +0400 Subject: [PATCH] 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) --- knex/knex-tests.ts | 1 + knex/knex.d.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/knex/knex-tests.ts b/knex/knex-tests.ts index a822149821..7ec53cbe3b 100644 --- a/knex/knex-tests.ts +++ b/knex/knex-tests.ts @@ -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'); diff --git a/knex/knex.d.ts b/knex/knex.d.ts index 6fd81b455f..9a16d3afc0 100644 --- a/knex/knex.d.ts +++ b/knex/knex.d.ts @@ -12,7 +12,7 @@ declare module "knex" { type Callback = Function; type Client = Function; - type Value = string|number|boolean|Date|Array|Array|Array|Array|Buffer; + type Value = string|number|boolean|Date|Array|Array|Array|Array|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; currentVersion(config?: MigratorConfig):Promise; } + + interface FunctionHelper { + now(): Raw; + } } export = Knex;