本文整理匯總了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);
}