当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript knex类代码示例

本文整理汇总了TypeScript中knex的典型用法代码示例。如果您正苦于以下问题:TypeScript knex类的具体用法?TypeScript knex怎么用?TypeScript knex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了knex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: makeKnex

export function makeKnex({ host, user, password, database }) {
  const knex = makeKnexConnection({
    client: 'pg',
    connection: {
      database,
      host,
      password: 'postgres',
      user,
    },
  })

  // @TODO: Figure out how to make this work with async await or Promises.
  // @TODO: See why migrations bugs out in tests.
  if (process.env.NODE_ENV !== 'test') {
    knex.migrate
      .rollback()
      .then(() => knex.migrate.latest())
      .then(() =>
        knex.seed
          .run()
          .then(() => knex)
          // tslint:disable-next-line:no-console
          .catch(e => console.error(e) && process.exit(1))
      )
  }

  return knex
}
开发者ID:marcusnielsen,项目名称:mn-server,代码行数:28,代码来源:knex.ts

示例2: beforeAll

    beforeAll(async () => {
        knex = Knex(DEFAULT_DB_CONFIG);
        await knex.migrate.latest();
        await knex.seed.run();

        const dbConfig = new DbConfig(DEFAULT_DB_CONFIG);
        container = new Container();

        container.bind<DbConfig>('DefaultDbConfig').toConstantValue(dbConfig);

        // container...
        container.bind<ICounterRepository>(TYPES.ICounterRepository).to(CounterRepository);

    });
开发者ID:baotaizhang,项目名称:fullstack-pro,代码行数:14,代码来源:counter-repository.test.ts

示例3: copyRunDbFixerScript

async function copyRunDbFixerScript(dbFileNamePath: string, backupDbPath: string): Promise<void> {
  await promisify(fs.copyFile)(dbFileNamePath, backupDbPath);
  // need to do this because cli runs migrations in .ts and augur-app runs migrations in .js
  const db: Knex = Knex({
    client: "sqlite3",
    connection: {
      filename: backupDbPath,
    },
    acquireConnectionTimeout: 5 * 60 * 1000,
    useNullAsDefault: true,
  });
  await db.raw("update knex_migrations set name = substr(name,1, length(name)-2) || 'js';");
  await db.destroy();
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:14,代码来源:file-operations.ts

示例4: config

  private config(): void {
    // Sets the global header `Server` as a middleware. We
    // are intentionally receiving and ignoring the `req`
    // parameter, indicated by the underscore.
    this.app.use((_, res, next): void => {
      res.set("Server", "TypeScript-rest");

      next();
    });

    // Initiatlize connection to the database and connect
    // the knex query builder to our objection models.
    const knex = Knex(Knexfile);
    Model.knex(knex);
  }
开发者ID:TechEmpower,项目名称:FrameworkBenchmarks,代码行数:15,代码来源:server.ts

示例5: knex

    knex(tableName?: string | Knex.Raw | Knex.QueryBuilder | undefined) {
        if (!knexInstance) {
            knexInstance = Knex({
                client: 'mysql',
                connection: {
                    host: DB_HOST,
                    user: DB_USER,
                    password: DB_PASS,
                    database: WORDPRESS_DB_NAME
                }
            })
        }

        return knexInstance(tableName)
    }
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:15,代码来源:wpdb.ts

示例6: test

test('should add a new record on #save()', async function (t) {
  // startup...
  const knex = Knex({ client: 'sqlite3', connection: { filename: ':memory:' } });

  Model.knex(knex);
  Models.One.app = 'myBlog';

  const m = new Migration({ tables: [] }, { tables: [Models.One.toJSON()] });
  Migration.run(knex, await m.up());

  const one = new Models.One({ myBoolean: 1, myDate: Date.now(), myDateTime: Date.now() });
  await one.save();
  const found = await Models.One.query().where('id', 1);

  // teardown...
  await knex.destroy();
  t.same(one, found[0]);
})
开发者ID:gitter-badger,项目名称:overland,代码行数:18,代码来源:model.ts

示例7: resetDatabase

  static resetDatabase(done) {
    let connection = knex({
      client    : 'mysql',
      connection: {
        user    : 'root',
        host    : '127.0.0.1',
        database: 'wetland_test',
      },
    });

    connection.raw('drop database wetland_test').then(function () {
      return connection.raw('create database wetland_test').then(() => {
        connection.destroy().then(() => {
          done();
        });
      });
    });
  }
开发者ID:RWOverdijk,项目名称:wetland,代码行数:18,代码来源:Schema.ts

示例8: knex

export function knex() {
    if (!knexInstance) {
        knexInstance = Knex({
            client: 'mysql',
            connection: {
                host: DB_HOST,
                user: DB_USER,
                password: DB_PASS,
                database: DB_NAME,
                typeCast: (field: any, next: any) => {
                    if (field.type == 'TINY' && field.length == 1) {
                        return (field.string() == '1'); // 1 = true, 0 = false
                    } 
                    return next();
                }
            }
        })    
    }

    return knexInstance
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:21,代码来源:db.ts

示例9: constructor

    constructor(dataBaseInfo: IConnection) {
        // PostgreSQL, MySQL, and SQLite3.
        
        
        // XXX::: Dont know about port
        let knex = Knex({
            client: dataBaseInfo.driver,
            connection: {
                host: dataBaseInfo.host,
                user: dataBaseInfo.username,
                password: dataBaseInfo.password,
                database: dataBaseInfo.database,
                charset: 'utf8'
            }
        });

        knex['_config'] = dataBaseInfo;
        // XXX::: todo for mongo
        // XXX::: todo for elastic
        
        this._connection = Bookshelf(knex);
    }
开发者ID:yogendrap,项目名称:PlZoo,代码行数:22,代码来源:Connection.ts

示例10: knexFactory

import config from './index';
import * as knexFactory from 'knex';
import Knex from 'knex';

const env = process.env['NODE_ENV'] || 'development',
  MIGRATIONS_TABLE = 'migrations',
  { DB_CONNECTION, PG_POOL_MIN, PG_POOL_MAX, PG_SEARCH_PATH } = config[env];


export const dbConfig = {
  client: 'pg',
  connection: DB_CONNECTION,
  pool: {
    min: PG_POOL_MIN,
    max: PG_POOL_MAX
  },
  searchPath: PG_SEARCH_PATH,
  migrations: {
    directory: './migrations',
    tableName: MIGRATIONS_TABLE
  },
  seeds: {
    directory: './seeds',
  }
};

const db: Knex = knexFactory(dbConfig);

export default db;
开发者ID:aYo-dev,项目名称:node-scaffold,代码行数:29,代码来源:database.ts

示例11: initDb

export async function initDb(knexConfig: knex.Config): Promise<any> {
  return await knex(knexConfig)
}
开发者ID:haimich,项目名称:billy,代码行数:3,代码来源:dbProvider.ts

示例12: setupDb

export async function setupDb(): Promise<any> {
  const config = await get('knex')
  const db = knex(config)
  await db.migrate.latest()
}
开发者ID:haimich,项目名称:billy,代码行数:5,代码来源:dbProvider.ts

示例13: knexLib

ďťż

import * as knexLib from "knex";
import {dbConfig} from "../../config"

export var knex = knexLib(dbConfig);
    
开发者ID:DominicBisset,项目名称:BigLeagueServer,代码行数:6,代码来源:knex.ts

示例14: Knex

import * as GeoJSON from 'geojson';
import * as Knex from 'knex';
import * as KPG from 'knex-postgis';

const knex: Knex = Knex({ dialect: 'pg' });
const st: KPG.KnexPostgis = KPG(knex);

const point: GeoJSON.Point = {
  type: 'Point',
  coordinates: [23.773206, 61.506005],
  crs: {
    type: 'name',
    properties: {
      name: 'EPSG:4326'
    }
  }
};

const wktPoint = 'POINT(23.773206 61.506005)';

knex('geometries')
  .select(st.area('wkb_geometry').as('area'))
  .then(console.log);

// Can't be done because of Knex typings
// knex('geometries')
//   .select('name')
//   .where(st.area('wkb_geometry'), '>', 0.1)

knex('geometries')
  .select(st.asText('wkb_geometry'))
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:knex-postgis-tests.ts

示例15: Knex

const configInit = (knexConfig) => {
  knex = Knex(knexConfig);
  Model.knex(knex);
  return Promise.resolve(Model);
};
开发者ID:MarcDeletang,项目名称:bedrock,代码行数:5,代码来源:PostgresWrapper.ts


注:本文中的knex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。