本文整理汇总了TypeScript中objection.Model.knex方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Model.knex方法的具体用法?TypeScript Model.knex怎么用?TypeScript Model.knex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类objection.Model
的用法示例。
在下文中一共展示了Model.knex方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeAll
beforeAll(() => {
dotenv.config();
knx = knex({
client: "pg",
connection: `${process.env.DATABASE_URL}_test`,
});
Model.knex(knx);
});
示例2: 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);
}
示例3: 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]);
})
示例4: require
import * as knex from 'knex';
import { Model } from 'objection';
const config = require('../../../../../db/config');
Model.knex(knex(config[process.env.NODE_ENV || 'development']));
示例5: knex
import knex from "knex";
import { Model } from "objection";
import appConfig from "../../../../app-config";
export const pg = knex({
client: "pg",
version: "9.6",
connection: {
host: appConfig.databaseHost,
database: appConfig.databaseName,
user: appConfig.databaseUser,
password: appConfig.databasePassword,
},
});
Model.knex(pg);
export { UserModel } from "./user";
export { ShapeModel } from "./shape";
export { DocumentModel } from "./document";
示例6: knex
import knex from "knex";
import morgan from "morgan";
import { Model } from "objection";
import schema from "./schema";
dotenv.config();
const PORT = process.env.PORT || 3000;
const knx = knex({
client: "pg",
connection: process.env.DATABASE_URL,
});
Model.knex(knx);
const graphqlOptions: ExpressGraphQLOptionsFunction = (request) => ({
context: { request, knex },
schema,
});
const app = express();
app.use(morgan("dev"));
app.use("/graphql", bodyParser.json(), graphqlExpress(graphqlOptions));
app.use(express.static("public"));
// tslint:disable-next-line:no-console
app.listen(PORT, () => console.log(`Listening on :${PORT}`));
示例7: Knex
const configInit = (knexConfig) => {
knex = Knex(knexConfig);
Model.knex(knex);
return Promise.resolve(Model);
};