本文整理汇总了TypeScript中bookshelf类的典型用法代码示例。如果您正苦于以下问题:TypeScript bookshelf类的具体用法?TypeScript bookshelf怎么用?TypeScript bookshelf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了bookshelf类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Knex
/// <reference path="bookshelf.d.ts" />
/// <reference path="../knex/knex.d.ts" />
import * as Knex from 'knex';
import * as Bookshelf from 'bookshelf';
var knex = Knex({
client: 'sqlite3',
connection: {
filename: ':memory:',
},
});
// Examples
var bookshelf = Bookshelf(knex);
class User extends bookshelf.Model<User> {
get tableName() { return 'users'; }
messages() : Bookshelf.Collection<Posts> {
return this.hasMany(Posts);
}
}
class Posts extends bookshelf.Model<Posts> {
get tableName() { return 'messages'; }
tags() : Bookshelf.Collection<Tag> {
return this.belongsToMany(Tag);
}
}
示例2: knex
import * as knex from "knex";
import {database as knexConnection} from "../knex/knexfile"
import * as bookshelf from "bookshelf"
let dbConnection = knex(knexConnection);
let db = bookshelf(dbConnection);
db.plugin('registry');
export {db};
示例3: 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));
示例4: bookshelf
ďťżimport {knex} from "./knex";
import * as bookshelf from "bookshelf";
export var db = bookshelf(knex);
示例5: 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);
}