Add docs
This commit is contained in:
parent
dea07f3a02
commit
98690a4881
58
lib/sql.js
58
lib/sql.js
|
@ -21,6 +21,11 @@ BaseSQL.prototype.queryOne = function (sql, callback) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Look up the data source by model name
|
||||
* @param model The model name
|
||||
* @returns {DataSource} The data source
|
||||
*/
|
||||
BaseSQL.prototype.dataSource = function(model) {
|
||||
var m = this._models[model];
|
||||
if(!m) {
|
||||
|
@ -29,6 +34,11 @@ BaseSQL.prototype.dataSource = function(model) {
|
|||
return m.model.schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table name for a given model
|
||||
* @param model The model name
|
||||
* @returns {String} The table name
|
||||
*/
|
||||
BaseSQL.prototype.table = function (model) {
|
||||
var name = this.dataSource(model).tableName(model);
|
||||
var dbName = this.dbName;
|
||||
|
@ -38,6 +48,12 @@ BaseSQL.prototype.table = function (model) {
|
|||
return name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the column name for given model property
|
||||
* @param model The model name
|
||||
* @param property The property name
|
||||
* @returns {String} The column name
|
||||
*/
|
||||
BaseSQL.prototype.column = function (model, property) {
|
||||
var name = this.dataSource(model).columnName(model, property);
|
||||
var dbName = this.dbName;
|
||||
|
@ -47,6 +63,12 @@ BaseSQL.prototype.column = function (model, property) {
|
|||
return name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the corresponding property name for a given column name
|
||||
* @param model The model name
|
||||
* @param column The column name
|
||||
* @returns {*}
|
||||
*/
|
||||
BaseSQL.prototype.propertyName = function (model, column) {
|
||||
var props = this._models[model].properties;
|
||||
for(var p in props) {
|
||||
|
@ -57,10 +79,20 @@ BaseSQL.prototype.propertyName = function (model, column) {
|
|||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the id property name
|
||||
* @param model The model name
|
||||
* @returns {String} The id property name
|
||||
*/
|
||||
BaseSQL.prototype.idName = function (model) {
|
||||
return this.dataSource(model).idName(model);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the id column name
|
||||
* @param model The model name
|
||||
* @returns {String} The column name
|
||||
*/
|
||||
BaseSQL.prototype.idColumn = function (model) {
|
||||
var name = this.dataSource(model).idColumnName(model);;
|
||||
var dbName = this.dbName;
|
||||
|
@ -70,10 +102,21 @@ BaseSQL.prototype.idColumn = function (model) {
|
|||
return name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the escaped id column name
|
||||
* @param model The model name
|
||||
* @returns {String} the escaped id column name
|
||||
*/
|
||||
BaseSQL.prototype.idColumnEscaped = function (model) {
|
||||
return this.escapeName(this.dataSource(model).idColumnName(model));
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the id index (sequence number, starting from 1)
|
||||
* @param model The model name
|
||||
* @param prop The property name
|
||||
* @returns {Number} The id index, undefined if the property is not part of the primary key
|
||||
*/
|
||||
BaseSQL.prototype.id = function (model, prop) {
|
||||
var p = this._models[model].properties[prop];
|
||||
if(!p) {
|
||||
|
@ -82,14 +125,29 @@ BaseSQL.prototype.id = function (model, prop) {
|
|||
return p.id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Escape the name for the underlying database
|
||||
* @param name The name
|
||||
*/
|
||||
BaseSQL.prototype.escapeName = function (name) {
|
||||
throw new Error('escapeName method should be declared in adapter');
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the escaped table name
|
||||
* @param model The model name
|
||||
* @returns {String} the escaped table name
|
||||
*/
|
||||
BaseSQL.prototype.tableEscaped = function (model) {
|
||||
return this.escapeName(this.table(model));
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the escaped column name for a given model property
|
||||
* @param model The model name
|
||||
* @param property The property name
|
||||
* @returns {String} The escaped column name
|
||||
*/
|
||||
BaseSQL.prototype.columnEscaped = function (model, property) {
|
||||
return this.escapeName(this.column(model, property));
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue