本文整理汇总了TypeScript中knex类的典型用法代码示例。如果您正苦于以下问题:TypeScript knex类的具体用法?TypeScript knex怎么用?TypeScript knex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了knex类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: require
import * as knex from 'knex';
import { Model } from 'objection';
const config = require('../../../../../db/config');
Model.knex(knex(config[process.env.NODE_ENV || 'development']));
开发者ID:rosendi,项目名称:figure,代码行数:7,代码来源:objection.ts
示例17: extend
import * as libKnex from 'knex';
import * as pg from 'pg';
import { extend, _raw } from 'pg-extra';
import { isNil } from 'ramda';
import { db } from '../config';
const postgres = extend(pg);
export const pool = new postgres.extra.Pool(db);
export const knex = libKnex({ client: 'pg' });
/**
* Run a Knex query for a single result through the pool
* @param {object} query - A Knex query object
*/
export const getOneRaw = query => pool.one(_raw`${query}`);
/**
* Run a Knex query for multiple results through the pool
* @param {object} query - A Knex query object
*/
export const getManyRaw = query => pool.many(_raw`${query}`);
/**
* On a null query response throw an error to the response handler otherwise return
* @param {string} error - Error message to throw with
* @param {any} data - Response from query
*/
export const result = (error: string, data: any): never | any => {
if (isNil(data)) {
throw new Error(error);
开发者ID:benjambles,项目名称:my-own-world,代码行数:31,代码来源:index.ts
示例18: require
import registerApi from './api';
import * as bodyParser from 'body-parser';
import * as express from 'express';
import * as Knex from 'knex';
import * as morgan from 'morgan';
import { Model } from 'objection';
const knexConfig = require('../knexfile');
// Initialize knex.
export const knex = Knex(knexConfig.development);
// Create or migrate:
knex.migrate.latest();
// Bind all Models to a knex instance. If you only have one database in
// your server this is all you have to do. For multi database systems, see
// the Model.bindKnex method.
Model.knex(knex);
// Unfortunately the express-promise-router types are borked. Just require():
const router = require('express-promise-router')();
const app = express()
.use(bodyParser.json())
.use(morgan('dev'))
.use(router)
.set('json spaces', 2);
// Register our REST API.
registerApi(router);
// Error handling. The `ValidationError` instances thrown by objection.js have a `statusCode`
开发者ID:jpawlik,项目名称:objection.js,代码行数:31,代码来源:app.ts
示例19: require
import * as bookshelf from "bookshelf";
import * as knex from "knex";
import * as pg from "pg";
pg.defaults.ssl = true;
// Fix for parsing of numeric fields
pg.types.setTypeParser(1700, "text", parseFloat);
import knexfile = require("./knexfile");
const dbConfig = knexfile[process.env.NODE_ENV];
export = bookshelf(knex(dbConfig));
开发者ID:CMUBigLab,项目名称:cmuNodeFbot,代码行数:14,代码来源:bookshelf.ts
示例20: Knex
/// <reference path='knex.d.ts' />
/// <reference path='../lodash/lodash-3.10.d.ts' />
import * as Knex from 'knex';
import * as _ from 'lodash';
// Initializing the Library
var knex = Knex({
client: 'sqlite3',
connection: {
filename: "./mydb.sqlite"
}
});
var knex = Knex({
debug: true,
client: 'mysql',
connection: {
socketPath : '/path/to/socket.sock',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
});
// Mariasql configuration
var knex = Knex({
debug: true,
client: 'mariasql',
connection: {
开发者ID:StrideSpark,项目名称:DefinitelyTyped,代码行数:31,代码来源:knex-tests.ts
注:本文中的knex类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论