本文整理汇总了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
}
示例2: Knex
const getDb = (config: DbConfig): Knex => {
if (!_db) {
_db = Knex(config.getConfiguration());
}
return _db;
};
示例3: Knex
test.beforeEach(t => {
t.context.db = Knex({
client: 'sqlite3',
connection: {
filename: ':memory:'
}
});
});
示例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,
});
}
}
示例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);
});
示例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();
}
示例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);
}
示例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)
}
示例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]);
})
示例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();
});
});
});
}