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


TypeScript knex.default方法代码示例

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


在下文中一共展示了knex.default方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Knex

const getDb = (config: DbConfig): Knex => {

    if (!_db) {
        _db = Knex(config.getConfiguration());
    }

    return _db;
};
开发者ID:baotaizhang,项目名称:fullstack-pro,代码行数:8,代码来源:abstract-repository.ts

示例3: Knex

test.beforeEach(t => {
  t.context.db = Knex({
    client: 'sqlite3',
    connection: {
      filename: ':memory:'
    }
  });
});
开发者ID:gitter-badger,项目名称:overland,代码行数:8,代码来源:model.ts

示例4: createKnex

function createKnex(networkId: string, dbPath: string): Knex {
  logger.info(dbPath);
  if (process.env.DATABASE_URL) {
    // Be careful about non-serializable transactions. We expect database writes to be processed from the blockchain, serially, in block order.
    return Knex({
      client: "pg",
      connection: process.env.DATABASE_URL,
      postProcessResponse: postProcessDatabaseResults,
    });
  } else {
    sqlite3.verbose();
    return Knex({
      client: "sqlite3",
      connection: {
        filename: dbPath,
      },
      acquireConnectionTimeout: 5 * 60 * 1000,
      useNullAsDefault: true,
      postProcessResponse: postProcessDatabaseResults,
    });
  }
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:22,代码来源:check-and-initialize-augur-db.ts

示例5: 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

示例6: 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

示例7: 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

示例8: knexInstance

    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

示例9: function

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

示例10: 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


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