knex/lib/util/make-client.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-04-22 15:39:29 -04:00
'use strict';
2015-05-09 13:58:18 -04:00
var assign = require('lodash/object/assign');
var inherits = require('inherits');
2015-05-09 13:58:18 -04:00
// Ensure the client has fresh objects so we can tack onto
// the prototypes without mutating them globally.
module.exports = function makeClient(ParentClient) {
if (typeof ParentClient.prototype === 'undefined') {
2015-05-09 13:58:18 -04:00
throw new Error('A valid parent client must be passed to makeClient');
}
function Client(config) {
2015-05-09 13:58:18 -04:00
ParentClient.call(this, config);
}
2015-05-09 13:58:18 -04:00
inherits(Client, ParentClient);
function Formatter(client) {
2015-05-09 13:58:18 -04:00
Formatter.super_.call(this, client);
}
2015-05-09 13:58:18 -04:00
inherits(Formatter, ParentClient.prototype.Formatter);
function QueryBuilder(client) {
2015-05-09 13:58:18 -04:00
QueryBuilder.super_.call(this, client);
}
2015-05-09 13:58:18 -04:00
inherits(QueryBuilder, ParentClient.prototype.QueryBuilder);
function SchemaBuilder(client) {
2015-05-09 13:58:18 -04:00
SchemaBuilder.super_.call(this, client);
}
2015-05-09 13:58:18 -04:00
inherits(SchemaBuilder, ParentClient.prototype.SchemaBuilder);
function SchemaCompiler(client, builder) {
2015-05-09 13:58:18 -04:00
SchemaCompiler.super_.call(this, client, builder);
}
2015-05-09 13:58:18 -04:00
inherits(SchemaCompiler, ParentClient.prototype.SchemaCompiler);
function TableBuilder(client, method, tableName, fn) {
2015-05-09 13:58:18 -04:00
TableBuilder.super_.call(this, client, method, tableName, fn);
}
2015-05-09 13:58:18 -04:00
inherits(TableBuilder, ParentClient.prototype.TableBuilder);
function TableCompiler(client, tableBuilder) {
2015-05-09 13:58:18 -04:00
TableCompiler.super_.call(this, client, tableBuilder);
}
2015-05-09 13:58:18 -04:00
inherits(TableCompiler, ParentClient.prototype.TableCompiler);
function ColumnBuilder(client, tableBuilder, type, args) {
2015-05-09 13:58:18 -04:00
ColumnBuilder.super_.call(this, client, tableBuilder, type, args);
}
2015-05-09 13:58:18 -04:00
inherits(ColumnBuilder, ParentClient.prototype.ColumnBuilder);
function ColumnCompiler(client, tableCompiler, columnBuilder) {
2015-05-09 13:58:18 -04:00
ColumnCompiler.super_.call(this, client, tableCompiler, columnBuilder);
}
2015-05-09 13:58:18 -04:00
inherits(ColumnCompiler, ParentClient.prototype.ColumnCompiler);
assign(Client.prototype, {
2015-05-09 13:58:18 -04:00
Formatter: Formatter,
QueryBuilder: QueryBuilder,
SchemaBuilder: SchemaBuilder,
SchemaCompiler: SchemaCompiler,
2015-05-09 13:58:18 -04:00
TableBuilder: TableBuilder,
TableCompiler: TableCompiler,
ColumnBuilder: ColumnBuilder,
ColumnCompiler: ColumnCompiler
2015-05-09 13:58:18 -04:00
});
2015-05-09 13:58:18 -04:00
return Client;
};