Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. declare module 'knex' {
  2.     export interface IReferencesDefinition {
  3.         inTable(tableName: string)
  4.     }
  5.  
  6.     export interface IForeignDefinition {
  7.         references(columnName: string): IReferencesDefinition
  8.     }
  9.  
  10.     export interface IColumnDefinition {
  11.         primary(): void
  12.         notNullable(): void
  13.     }
  14.  
  15.     export interface ITableDefinitionCallback {
  16.         (table: ITableDefinition): void
  17.     }
  18.    
  19.     export type IIntegerDefinition = IColumnDefinition & {
  20.         unsigned(): IColumnDefinition
  21.     }
  22.  
  23.     export interface ITableDefinition {
  24.         integer(columnName: string): IIntegerDefinition
  25.         timestamps(): void
  26.         increments(columnName?: string): IColumnDefinition
  27.         enum(columnName: string, values: string[]): IColumnDefinition
  28.         timestamp(columnName: string): IColumnDefinition
  29.         string(columnName: string, length: number): IColumnDefinition
  30.         foreign(columnName: string): IForeignDefinition
  31.     }
  32.  
  33.     export interface IKnexSchema {
  34.         createTable(tableName: string, callback: ITableDefinitionCallback): Promise<void>
  35.     }
  36.  
  37.     export type IQuery = {
  38.         where(where: Object): IQuery
  39.         first(...columns: string[]): IQuery
  40.     } & Promise<any>
  41.  
  42.     export type IQueryBuilder = IQuery & {
  43.         insert(row: Object): Promise<any> & IQuery
  44.         update(row: Object): Promise<any> & IQuery
  45.     }
  46.  
  47.     export interface IKnex {
  48.         schema: IKnexSchema
  49.         (tableName: string): IQueryBuilder
  50.     }
  51.  
  52.     export interface IConnectionOptions {
  53.         host: string
  54.         user: string
  55.         password: string
  56.         database: string
  57.     }
  58.  
  59.     export interface IKnexOptions {
  60.         client: string
  61.         connection: IConnectionOptions
  62.     }
  63.  
  64.     export default function knex(IKnexOptions): IKnex
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement