Class Index | File Index

Classes


Class SQL

Base class for all SQL database query types. This class is an abstract class for all SQL adapter implementations. An instance of SQL provides methods for querying, updating and removing a datase
Defined in: sql.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
SQL()
Field Summary
Field Attributes Field Name and Description
 
sql
the current sql query string.
Method Summary
Method Attributes Method Name and Description
<static>  
SQL.addColumn()
Create an add column statement

See your client adpater for parameters!

<static>  
Create a add foreign key statement

See your client adpater for parameters!

<static>  
Create a add primary key statement

See your client adpater for parameters!

<static>  
SQL.addUnique()
Create a add unique constraint statement

See your client adpater for parameters!

<static>  
Create an alter column statement

See your client adpater for parameters!

<static>  
SQL.alterTable(table, db)
Alter a table.
 
and(options)
Add and operator, one does not need to call this but it is provided for clarity.
 
avg(options)
 
between(options)
Add a between check for a column.
 
bitAnd(options)
Helper to add a bit and clause.
 
bitOr(options)
 
bitXor(options)
Helper to add a bit xor clause.
 
Clear the current query.
 
Clear the having clause from the query.
 
Clear the limit clause on this SQL query
 
Removes the offset clause from a query.
 
Clears the order clause
 
Close the connection.
<static>  
SQL.column()
Create a column statement

See your client adpater for parameters!

 
count(options)
Add a count cause to the select portion of the query.
<static>  
SQL.createTable(table, db)
Create a table.
 
crossJoin(table)
Add a cross join to another table
 
Select on dinstict results, same is distinct clause in SQL statment.
<static>  
SQL.dropColumn()
Create a drop column statement

See your client adpater for parameters!

<static>  
Create a drop foreign key statement

See your client adpater for parameters!

<static>  
Create a drop primary key statement

See your client adpater for parameters!

<static>  
SQL.dropTable(table, db)
Drop a table.
<static>  
SQL.dropUnique()
Create a drop unique constraint statement

See your client adpater for parameters!

 
end()
Performs clean up to add any needed protions of a query if not provided.
 
eq(options)
Use to find rows that equal a particular value
 
exec()
Executes the query, when finished the promise callback is called if the query errors then the promise error is called.
 
find(query)
This is a wrapper to enable using an object to query a dataset.
<static>  
SQL.foreignKey()
Create a foreign key statement

See your client adpater for parameters!

 
format(sql, array)
Formats and escapes query string.
<static>  
SQL.format(sql, array)
Formats and escapes query string.
 
fullJoin(table, options)
Add a full join to another table
 
fullOuterJoin(table, options)
Add a full outer join to another table
<static>  
Retrieve the last inserted id on a database.
 
group(key, having)
Perform a group operation.
 
groupAndAvg(key, having)
Helper to add a group and avg clause.
 
groupAndBitAnd(key, having)
Helper to add a group and bit and clause.
 
groupAndBitOr(key, having)
Helper to add a group and bit or clause.
 
groupAndBitXor(key, having)
Helper to add a group and bit xor clause.
 
groupAndCount(key, having)
Helper to add a group and count clause.
 
groupAndMax(key, having)
Helper to add a group and max clause.
 
groupAndMin(key, having)
Helper to add a group and min clause.
 
groupAndStd(key, having)
Helper to add a group and std clause.
 
groupAndStdDev(key, having)
Helper to add a group and std dev clause.
 
groupAndStdDevPop(key, having)
Helper to add a group and std dev pop clause.
 
groupAndStdDevSamp(key, having)
Helper to add a group and std dev samp clause.
 
groupAndSum(key, having)
Helper to add a group and sum clause.
 
groupAndVariance(key, having)
Helper to add a group and variance clause.
 
groupAndVarPop(key, having)
Helper to add a group and var pop clause.
 
groupAndVarSamp(key, having)
Helper to add a group and var samp clause.
 
gt(options)
Use to find rows that are greater than a particular value
 
gte(options)
Add a check for a value greater than or equal to a particular value.
 
having(options)
Add a having clause, this is only valid on queries that contain a group clause.
 
innerJoin(table, options)
Add an inner join to another table
 
is(options)
Specify an is clause.
 
isNot(options)
Add is not clause
 
isNotNull(options)
Check if a column is not null.
 
isNull(options)
Add is null check
<static>  
Check if a type is a valid type for this adapter.
 
join(table, options)
This is an alias for an inner join.
 
leftJoin(table, options)
Add a left join to another table
 
leftOuterJoin(table, options)
Add a left outer join to another table
 
like(options)
Add a like clause.
 
limit(limit, offset)
Use to limit the number of results returned.
 
logicGroup(query)
Add a logic group to a query.
 
lt(options)
Add a check for a value less than a particular value.
 
lte(options)
Add a check for a value less than or equal to a particular value.
 
max(options)
Helper to add a max clause.
 
min(options)
Helper to add a min clause.
 
naturalJoin(table)
Add a natural join to another table
 
Add a natural left join to another table
 
Add a natural right join to another table
 
neq(options)
Use to find rows that have a column that do not equal a particular value.
 
notBetween(@param)
Add a not between check for a column.
 
notIn(options)
Add a not in clause
 
notLike(options)
Add a not like clause.
 
offset(offset)
Specify an offset, offset says to skip that many rows before beginning to return rows to the client.
 
or(query)
Use to add an or clause
 
order(options)
To be used with queries to specify an order of the result set.
 
orderBy(options)
<static>  
SQL.primaryKey()
Create a primary key statement

See your client adpater for parameters!

 
remove(tables, query)
Signify this SQL instance as a delete statement

Cannot be used in combination with update, or find queries.

 
rightJoin(table, options)
Add a right join to another table
 
rightOuterJoin(table, options)
Add a right outer join to another table
<static>  
SQL.save(table, object, db)
Perform a batch insert into a table the objects.
<static>  
SQL.schema(tableName, db)
Retrieve and create a moose.Table from a schema stored in the database.
 
select(columns, options)
Use to return particular columns from a query, i.e.
 
std(options)
Helper to add a std clause.
 
stdDev(options)
Helper to add a std dev clause.
 
stdDevPop(options)
Helper to add a std dev clause.
 
stdDevSamp(options)
Helper to add a std dev samp clause.
 
sum(options)
Helper to add a sum clause.
<static>  
SQL.unique()
Create a unique constraint statement

See your client adpater for parameters!

 
update(values, query)
Signify this SQL instance as an update statement.
 
variance(options)
Helper to add a variance clause.
 
varPop(options)
Helper to add a var pop clause.
 
varSamp(options, options)
Helper to add a var samp clause.
 
where(options)
Set the where clause of the query.
Class Detail
SQL()
Field Detail
{String} sql
the current sql query string.
Method Detail
<static> SQL.addColumn()
Create an add column statement

See your client adpater for parameters!


<static> SQL.addForeignKey()
Create a add foreign key statement

See your client adpater for parameters!


<static> SQL.addPrimaryKey()
Create a add primary key statement

See your client adpater for parameters!


<static> SQL.addUnique()
Create a add unique constraint statement

See your client adpater for parameters!


<static> SQL.alterColumn()
Create an alter column statement

See your client adpater for parameters!


<static> {comb.Promise} SQL.alterTable(table, db)
Alter a table.
Parameters:
{moose.Table} table
the table to alter on the database
{moose.adapters.client.Query|moose.adapters.client.TransactionQuery} db
the conneciton to the database.
Returns:
{comb.Promise} called back with results or the error call back is called with an error.

{SQL} and(options)
Add and operator, one does not need to call this but it is provided for clarity.
//select * from test where x <= 1 and y >= 1
sql.lte({x : 1}).gte({y : 1});
sql.lte({x : 1}).and({y : { gte : 1}});
sql.lte({x : 1}).and().gte({y : 1});
Parameters:
{Object} options Optional
query to append after the and.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} avg(options)
//select avg(name) as name_avg from test
sql.avg("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a avg is added for that particular columns, an array adds a avg for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} between(options)
Add a between check for a column.
//select * from test where x >= 1 and x <= 5
sql.between({x : [1,5]});
//select * from test where x >= 'a' and x <= 'b'
sql.find({x : {between : ["a","b"]}});
Parameters:
options
options key value pairs where the key is coulmn name and the value is an array of two values, first value in the array represents the gte value and the second value being the lte value.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} bitAnd(options)
Helper to add a bit and clause.
//select bit_and(name) as name_bit_and from test
sql.bitAnd("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a bit and is added for that particular columns, an array adds a bit and for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} bitOr(options)
//select bit_or(name) as name_bit_or from test
sql.bitOr("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a bit or is added for that particular columns, an array adds a count for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} bitXor(options)
Helper to add a bit xor clause.
//select bit_xor(name) as name_bit_xor from test
sql.bitXor("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a bit xor is added for that particular columns, an array adds a bit xor for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

clear()
Clear the current query.

{SQL} clearHaving()
Clear the having clause from the query.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} clearLimit()
Clear the limit clause on this SQL query
Returns:
{SQL} this to allow chaining of query elements.

{SQL} clearOffset()
Removes the offset clause from a query.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} clearOrder()
Clears the order clause
Returns:
{SQL} this to allow chaining of query elements.

close()
Close the connection.

<static> SQL.column()
Create a column statement

See your client adpater for parameters!


{SQL} count(options)
Add a count cause to the select portion of the query.
//select count(name) as name_count from test
sql.count("name");
//select count(*) as count from test
sql.count();
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a count is added for that particular columns, an array adds a count for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

<static> {comb.Promise} SQL.createTable(table, db)
Create a table.
Parameters:
{moose.Table} table
the table to create on the database
{moose.adapters.client.Query|moose.adapters.client.TransactionQuery} db
the conneciton to the database.
Returns:
{comb.Promise} called back with results or the error call back is called with an error.

{SQL} crossJoin(table)
Add a cross join to another table
//select * from test cross join test2
sql.crossJoin("test2");
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} distinct()
Select on dinstict results, same is distinct clause in SQL statment.
//select distinct * from test where id = 1
sql.find({id : 1}).distinct();
//select distinct test.* from test inner join test2 on test.id=test2.id where test2.other = 1
sql.join("test2", {id : "id"}).where({"test2.other" : 1}).select("test.*").distinct();
Returns:
{SQL} this to allow chaining of query elements.

<static> SQL.dropColumn()
Create a drop column statement

See your client adpater for parameters!


<static> SQL.dropForeignKey()
Create a drop foreign key statement

See your client adpater for parameters!


<static> SQL.dropPrimaryKey()
Create a drop primary key statement

See your client adpater for parameters!


<static> {comb.Promise} SQL.dropTable(table, db)
Drop a table.
Parameters:
{moose.Table} table
the table to drop on the database
{moose.adapters.client.Query|moose.adapters.client.TransactionQuery} db
the conneciton to the database.
Returns:
{comb.Promise} called back with results or the error call back is called with an error.

<static> SQL.dropUnique()
Create a drop unique constraint statement

See your client adpater for parameters!


{SQL} end()
Performs clean up to add any needed protions of a query if not provided.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} eq(options)
Use to find rows that equal a particular value
//select * from test where x = 0");
sql.eq({x : 0});
sql.find({x : 0});
Parameters:
{Object} options
object with key\ and value\
Returns:
{SQL} this to allow chaining of query elements.

{comb.Promise} exec()
Executes the query, when finished the promise callback is called if the query errors then the promise error is called.
Returns:
{comb.Promise} called back with results or the error call back is called with an error.

{SQL} find(query)
This is a wrapper to enable using an object to query a dataset. The hash can contain the name of any querying function as a key, and the value to look for as the value. When using find it signifies this SQL instance as a query.

Cannot be used in combination with update, or remove queries.

;
 var sql = new SQL("test", db);

//select * from test
sql.find();
//select * from test where id = 1;
sql.find({id : 1});
//select * from test where x != 0
sql.find({x : {neq : 0}});
//select * from test where id in (1,2,3,4,5)
sql.find({id : [1,2,3,4,5]});
 //select distinct * from test where id = 1
sql.find({id : 1}).distinct();
//select * from test where a >= 'b' limit 1
sql.find({a : {gte : "b"}}).limit(1);
//select * from test where flag is unknown
sql.find({flag : {is : "unknown"}});
//select * from test where flag is not unknown
sql.find({flag : {isNot : "unknown"}});
//select * from test where flag is false and flag is not unknown and anotherFlag is null and yetAnotherFlag is not null
sql.find({flag : {is : false}, flag2 : {isNot : "unknown"}, anotherFlag : {isNull : true}, yetAnotherFlag : {isNotNull : true}});
//select * from test where firstName like 'bob' and lastName not like 'henry'
sql.find({firstName : {like : 'bob'}, lastName : {notLike : "henry"}});
//select * from test where firstName like 'bob' and lastName not like 'henry'
sql.find({firstName : {like : 'bob'}, lastName : {notLike : "henry"}});
Parameters:
{Object} query Optional
query to limit result set.
Returns:
{SQL} this to allow chaining of query elements.

<static> SQL.foreignKey()
Create a foreign key statement

See your client adpater for parameters!


{String} format(sql, array)
Formats and escapes query string.
Parameters:
{String} sql
the sql to format
{Array} array
of values to place in the query.
Returns:
{String} the formatted string.

<static> {String} SQL.format(sql, array)
Formats and escapes query string.
Parameters:
{String} sql
the sql to format
{Array} array
of values to place in the query.
Returns:
{String} the formatted string.

{SQL} fullJoin(table, options)
Add a full join to another table
//select * from test full join test2 on test.id=test2.id
sql.fullJoin("test2", {id : "id"});
//select * from test full join test2 using (id, name)
sql.fullJoin("test2", ["id", "name"]);
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
{Array|Object} options
When an array is passed in the a using clause is used to specify the columns to join on, of an object is passed in then it is the same as using an on clause;
Returns:
{SQL} this to allow chaining of query elements.

{SQL} fullOuterJoin(table, options)
Add a full outer join to another table
//select * from test full outer join test2 on test.id=test2.id
sql.fullOuterJoin("test2", {id : "id"});
//select * from test full outer join test2 using (id, name)
sql.fullOuterJoin("test2", ["id", "name"]);
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
{Array|Object} options
When an array is passed in the a using clause is used to specify the columns to join on, of an object is passed in then it is the same as using an on clause;
Returns:
{SQL} this to allow chaining of query elements.

<static> {comb.Promise} SQL.getLastInsertId(db)
Retrieve the last inserted id on a database.
Parameters:
{moose.adapters.client.Query|moose.adapters.client.TransactionQuery} db
the conneciton to the database.
Returns:
{comb.Promise} called back with id or the error call back is called with an error.

{SQL} group(key, having)
Perform a group operation.
//select * from test group by name
sql.group("name");
//select * from test group by name, age
sql.group(["name", "age"]);
//select * from test group by name having name = 'bob'
sql.group("name", {name : "bob"});
//select * from test group by name, age having age >= 10 and age <= 20
sql.group(["name", "age"], {age : {between : [10, 20]}});
Parameters:
{String|Array} key
specify the columns to group on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndAvg(key, having)
Helper to add a group and avg clause.
//select *, avg(name) as name_avg from test group by name
sql.groupAndAvg("name");
Parameters:
{String|Array} key
specify the columns to group and avg on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndBitAnd(key, having)
Helper to add a group and bit and clause.
//select *, bit_and(name) as name_bit_and from test group by name
sql.groupAndBitAnd("name");
Parameters:
{String|Array} key
specify the columns to group and bit and on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndBitOr(key, having)
Helper to add a group and bit or clause.
//select *, bit_or(name) as name_bit_or from test group by name
sql.groupAndBitOr("name");
Parameters:
{String|Array} key
specify the columns to group and bit or on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndBitXor(key, having)
Helper to add a group and bit xor clause.
//select *, bit_xor(name) as name_bit_xor from test group by name
sql.groupAndBitXor("name");
Parameters:
{String|Array} key
specify the columns to group and bit xor on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndCount(key, having)
Helper to add a group and count clause.
//select *, count(name) as name_count from test group by name
sql.groupAndCount("name");
Parameters:
{String|Array} key
specify the columns to group and count on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndMax(key, having)
Helper to add a group and max clause.
//select *, max(name) as name_max from test group by name
sql.groupAndMax("name");
Parameters:
{String|Array} key
specify the columns to group and max on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndMin(key, having)
Helper to add a group and min clause.
//select *, min(name) as name_min from test group by name
sql.groupAndMin("name");
Parameters:
{String|Array} key
specify the columns to group and min on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndStd(key, having)
Helper to add a group and std clause.
//select *, std(name) as name_std from test group by name
sql.groupAndStd("name");
Parameters:
{String|Array} key
specify the columns to group and std on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndStdDev(key, having)
Helper to add a group and std dev clause.
//select *, stddev(name) as name_stddev from test group by name
sql.groupAndStdDev("name");
Parameters:
{String|Array} key
specify the columns to group and std dev on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndStdDevPop(key, having)
Helper to add a group and std dev pop clause.
//select *, stddev_pop(name) as name_stddev_pop from test group by name
sql.groupAndStdDevPop("name");
Parameters:
{String|Array} key
specify the columns to group and std dev pop on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndStdDevSamp(key, having)
Helper to add a group and std dev samp clause.
//select *, stddev_samp(name) as name_stddev_samp from test group by name
sql.groupAndStdDevSamp("name");
Parameters:
{String|Array} key
specify the columns to group and std dev samp on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndSum(key, having)
Helper to add a group and sum clause.
sql.groupAndSum("name");
//select *, sum(name) as name_sum from test group by name
Parameters:
{String|Array} key
specify the columns to group and sum on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndVariance(key, having)
Helper to add a group and variance clause.
//select *, variance(name) as name_variance from test group by name
sql.groupAndVariance("name");
Parameters:
{String|Array} key
specify the columns to group and variance on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndVarPop(key, having)
Helper to add a group and var pop clause.
//select *, var_pop(name) as name_var_pop from test group by name
sql.groupAndVarPop("name");
Parameters:
{String|Array} key
specify the columns to group and var pop on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} groupAndVarSamp(key, having)
Helper to add a group and var samp clause.
//select *, var_samp(name) as name_var_samp from test group by name
sql.groupAndVarSamp("name");
Parameters:
{String|Array} key
specify the columns to group and var samp on.
{Object} having
specify a having clause SQL#having.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} gt(options)
Use to find rows that are greater than a particular value
//select * from test where x > 0
sql.gt({x : 0});
sql.find({x : {gt : 0}});
Parameters:
{Object} options
keys values to add greater than checks for.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} gte(options)
Add a check for a value greater than or equal to a particular value.
//select * from test where x >= 0
sql.gte({x : 0});
sql.find({x : {gte : 0}});
Parameters:
{Object} options
key values to add greater than or equal to checks.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} having(options)
Add a having clause, this is only valid on queries that contain a group clause. Once a having clause has been added all query operations will be added to the having clause.
//select * from test group by name, age having age >= 10 and age <= 20
sql.group(["name", "age"]).having({age : {between : [10, 20]}});
//select * from test group by name, age having age >= 10 and age <= 20
sql.group(["name", "age"]).having().find({age : {between : [10, 20]}});
//select * from test group by name, age having age is null
sql.group(["name", "age"]).having().isNull("age");
Parameters:
{Object} options Optional
the query use on the having clause, same syntax as SQL#find, SQL#where;
Returns:
{SQL} this to allow chaining of query elements.

{SQL} innerJoin(table, options)
Add an inner join to another table
//select * from test inner join test2 on test.id=test2.id
sql.innerJoin("test2", {id : "id"});
//select * from test inner join test2 using (id, name)
sql.innerJoin("test2", ["id", "name"]);
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
{Array|Object} options
When an array is passed in the a using clause is used to specify the columns to join on, of an object is passed in then it is the same as using an on clause;
Returns:
{SQL} this to allow chaining of query elements.

{SQL} is(options)
Specify an is clause.
//select * from test where flag is true
sql.is({flag : true});
//select * from test where flag is false
sql.is({flag : false});
//select * from test where flag is null
sql.is({flag : null});
//select * from test where flag is unknown
sql.is({flag : "unknown"});
//select * from test where flag is true and otherFlag is false and anotherFlag is unknown and yetAnotherFlag is null
sql.is({flag : true, otherFlag : false, anotherFlag : "unknown", yetAnotherFlag : null});
//select * from test where flag is unknown
sql.find({flag : {is : "unknown"}});
//select * from test where flag is false and flag is not unknown and anotherFlag is null and yetAnotherFlag is not null
sql.is({flag : false}).isNot({flag : "unknown"}).isNull("anotherFlag").isNotNull("yetAnotherFlag
//select * from test where flag is not null and flag is true or flag is false
sql.isNotNull("flag").is({flag : true}).or({flag : {is : false}});
Parameters:
{Object} options
key value pairs to add is clauses for.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} isNot(options)
Add is not clause
//select * from test where flag is not true
sql.isNot({flag : true});
//select * from test where flag is not false
sql.isNot({flag : false});
 //select * from test where flag is not null
sql.isNot({flag : null});
//select * from test where flag is not unknown
sql.isNot({flag : "unknown"});
//select * from test where flag is not true and otherFlag is not false and anotherFlag is not unknown and yetAnotherFlag is not null
sql.isNot({flag : true, otherFlag : false, anotherFlag : "unknown", yetAnotherFlag : null});
//select * from test where flag is not unknown
sql.find({flag : {isNot : "unknown"}});
//select * from test where flag is false and flag is not unknown and anotherFlag is null and yetAnotherFlag is not null
sql.is({flag : false}).isNot({flag : "unknown"}).isNull("anotherFlag").isNotNull("yetAnotherFlag");
sql.find({flag : {is : false}, flag2 : {isNot : "unknown"}, anotherFlag : {isNull : true}, yetAnotherFlag : {isNotNull : true}});
//select * from test where flag is not null and flag is true or flag is false
sql.isNotNull("flag").is({flag : true}).or({flag : {is : false}});
Parameters:
{Object} options
key value pairs to add is not clauses for.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} isNotNull(options)
Check if a column is not null.
//select * from test where flag is not null
sql.isNotNull("flag");
//select * from test where flag is false and flag is not unknown and anotherFlag is null and yetAnotherFlag is not null
sql.is({flag : false}).isNot({flag : "unknown"}).isNull("anotherFlag").isNotNull("yetAnotherFlag
//select * from test where flag is not null and flag is true or flag is false
sql.isNotNull("flag").is({flag : true}).or({flag : {is : false}});
Parameters:
{String} options
name of column to check.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} isNull(options)
Add is null check
 //select * from test where flag is null
sql.isNull("flag");
//select * from test where flag is false and flag is not unknown and anotherFlag is null and yetAnotherFlag is not null
sql.is({flag : false}).isNot({flag : "unknown"}).isNull("anotherFlag").isNotNull("yetAnotherFlag
//select * from test where flag is not null and flag is true or flag is false
sql.isNotNull("flag").is({flag : true}).or({flag : {is : false}});
Parameters:
{String} options
column to check is not null.
Returns:
{SQL} this to allow chaining of query elements.

<static> {Boolean} SQL.isValidType()
Check if a type is a valid type for this adapter.
Returns:
{Boolean} true if it is a valid type, false otherwise.

{SQL} join(table, options)
This is an alias for an inner join.
//select * from test inner join test2 on test.id=test2.id
 sql.join("test2", {id : "id"});
//select * from test inner join test2 using (id, name)
 sql.join("test2", ["id", "name"]);
 //select * from test inner join test2 on test.id=test2.id left join test3 using (name)
sql.join("test2", {id : "id"}).leftJoin("test3", ["name"]);
//select * from test inner join test2 using (id, name) natural join test3
sql.join("test2", ["id", "name"]).naturalJoin("test3
//select * from test inner join test2 on test.id=test2.id left join test3 using (name) where x = 2 or x = 3
sql.join("test2", {id : "id"}).leftJoin("test3", ["name"]).eq({x : 2}).or({x : 3});
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
{Array|Object} options
When an array is passed in the a using clause is used to specify the columns to join on, of an object is passed in then it is the same as using an on clause;
Returns:
{SQL} this to allow chaining of query elements.

{SQL} leftJoin(table, options)
Add a left join to another table
//select * from test left join test2 on test.id=test2.id
sql.leftJoin("test2", {id : "id"});
//select * from test left join test2 using (id, name)
sql.leftJoin("test2", ["id", "name"]);
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
{Array|Object} options
When an array is passed in the a using clause is used to specify the columns to join on, of an object is passed in then it is the same as using an on clause;
Returns:
{SQL} this to allow chaining of query elements.

{SQL} leftOuterJoin(table, options)
Add a left outer join to another table
//select * from test left outer join test2 on test.id=test2.id
sql.leftOuterJoin("test2", {id : "id"});
//select * from test left outer join test2 using (id, name)
sql.leftOuterJoin("test2", ["id", "name"]);
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
{Array|Object} options
When an array is passed in the a using clause is used to specify the columns to join on, of an object is passed in then it is the same as using an on clause;
Returns:
{SQL} this to allow chaining of query elements.

{SQL} like(options)
Add a like clause.
//select * from test where name like 'bob'
sql.like({name : "bob"});
//select * from test where firstName like 'bob' and lastName not like 'henry'
sql.find({firstName : {like : 'bob'}, lastName : {notLike : "henry"}});
Parameters:
{Object} options
key, value pairs with the key representing a column, and the key represents the like condition.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} limit(limit, offset)
Use to limit the number of results returned.
//select * from test limit 1
sql.limit(1);
//select * from test limit 1 offset 10
sql.limit(1, 10);
//select * from test where a >= 'b' limit 1
sql.find({a : {gte : "b"}}).limit(1);
Parameters:
{Number} limit
the limit to specify on the query
{Number} offset Optional
SQL#offset
Returns:
{SQL} this to allow chaining of query elements.

{SQL} logicGroup(query)
Add a logic group to a query. The query that is passed in will be wrapped in parens.
//select * from test where (flag is not null and x = 1) or (x = 2)
sql.logicGroup({flag : {isNot : null}, x : 1}).or().logicGroup({x : 2});
Parameters:
{Object} query
query to group as one logical group;
Returns:
{SQL} this to allow chaining of query elements.

{SQL} lt(options)
Add a check for a value less than a particular value.
//select * from test where x < 1
sql.lt({x : 1});
sql.find({x : {lt : 1}});
Parameters:
{Object} options
key values to add less than checks.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} lte(options)
Add a check for a value less than or equal to a particular value.
//select * from test where x <= 1
sql.lte({x : 1});
sql.find({x : {lte : 1}});
Parameters:
{Object} options
key values to add less than or equal to checks.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} max(options)
Helper to add a max clause.
//select max(name) as name_max from test
sql.max("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a max is added for that particular columns, an array adds a max for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} min(options)
Helper to add a min clause.
//select min(name) as name_min from test
sql.min("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a min is added for that particular columns, an array adds a min for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} naturalJoin(table)
Add a natural join to another table
//select * from test natural full join test2
sql.naturalFullJoin("test2");
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} naturalLeftJoin(table)
Add a natural left join to another table
//select * from test natural left join test2
sql.naturalLeftJoin("test2");
//select * from test natural join test2
sql.naturalJoin("test2");
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} naturalRightJoin(table)
Add a natural right join to another table
//select * from test natural right join test2
sql.naturalRightJoin("test2");
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} neq(options)
Use to find rows that have a column that do not equal a particular value.
//select * from test where x != 0;
sql.neq({x : 0});
sql.find({x : {neq : 0}});
Parameters:
{Object} options
key value pairs to find columns no equal to a value
Returns:
{SQL} this to allow chaining of query elements.

{SQL} notBetween(@param)
Add a not between check for a column.
//select * from test where x <= 1 and x >= 5
sql.notBetween({x : [1,5]});
//select * from test where x <= 'a' and x >= 'b'
sql.notBetween({x : ["a","b"]});
//select * from test where x <= 'a' and x >= 'b'
sql.find({x : {notBetween : ["a","b"]}});
Parameters:
@param
options options key value pairs where the key is coulmn name and the value is an array of two values, first value in the array represents the lte value and the second value being the gte value.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} notIn(options)
Add a not in clause
//select * from test where id not in (1,2,3,4,5)
sql.notIn({id : [1,2,3,4,5]});
sql.find({id : {notIn : [1,2,3,4,5]}});
//select * from test where id not in (1,2,3,4,5) and id2 in (6,7,8,9,10)
sql.notIn({id : [1,2,3,4,5]}).in({id2 : [6,7,8,9,10]});
//select * from test where id not in (1,2,3,4,5) and id2 not in (6,7,8,9,10)
sql.notIn({id : [1,2,3,4,5], id2 : [6,7,8,9,10]});
//select * from test where id not in (select id2 from test2 where name >= 'A' and name <= 'B')
sql.notIn({id : new Mysql("test2", db).select("id2").between({name : ["A", "B"]})});
Parameters:
{Object} options
options key value pairs where the key is coulmn name and the value is an array of values.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} notLike(options)
Add a not like clause.
//select * from test where name not like 'bob'
sql.notLike({name : "bob"});
//select * from test where firstName like 'bob' and lastName not like 'henry'
sql.find({firstName : {like : 'bob'}, lastName : {notLike : "henry"}});
Parameters:
{Object} options
key, value pairs with the key representing a column, and the key represents the not like condition.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} offset(offset)
Specify an offset, offset says to skip that many rows before beginning to return rows to the client. If both offset and limit are used, then offset rows are skipped before starting to count the limit rows that are returned
//select * from test where a >= 'b' offset 10
sql.find({a : {gte : "b"}}).offset(10);
Parameters:
{Number} offset
the number to offset the result set by.
Returns:
{SQL} this to allow chaining of query elements.

or(query)
Use to add an or clause
//select * from test where x <= 1 and y >= 1
 sql.lte({x : 1}).or({y : {gte : 1}});
 sql.lte({x : 1}).or().gte({y : 1});
Parameters:
{Object} query
added after the or clause

{SQL} order(options)
To be used with queries to specify an order of the result set.
//select * from test order by x
sql.order("x");
//select * from test order by x desc
sql.order({x : "desc"});
//select * from test order by x, y
sql.order(["x", "y"]);
//select * from test order by x, y desc
sql.order(["x", {y : "desc"}]);
//select * from test order by x desc, y desc
sql.order([{x : "desc"},{y : "desc"}]);
//select * from test order by x, y, z desc
sql.order("x").order("y").order({z : "desc"});
Parameters:
{String|Array|Object} options
see example for uses of each.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} orderBy(options)
Parameters:
options
Returns:
{SQL} this to allow chaining of query elements.

<static> SQL.primaryKey()
Create a primary key statement

See your client adpater for parameters!


{SQL} remove(tables, query)
Signify this SQL instance as a delete statement

Cannot be used in combination with update, or find queries.

//delete from test
sql.remove();
//delete from test where x >= 1 and x <= 5
sql.remove(null, {x : {between : [1,5]}});
//delete from test where x >= 1 and x <= 5
sql.remove().where({x : {between : [1,5]}});
//delete from test where x >= 1 and x <= 5
sql.remove().find({x : {between : [1,5]}});
//delete test from test inner join test2 on test.flag=test2.false
sql.remove().join("test2", {flag : false});
//delete test, test2 from test inner join test2 on test.flag=test2.false
sql.remove("test2").join("test2", {flag : false});
Parameters:
{String|Array} tables Optional, Default: null
Should only be used to specify the removal of items from multiple tables.
{Object} query Optional
Use to limit the rows deleted SQL#where
Returns:
{SQL} this to allow chaining of query elements.

{SQL} rightJoin(table, options)
Add a right join to another table
//select * from test right join test2 on test.id=test2.id
sql.rightJoin("test2", {id : "id"});
//select * from test right join test2 using (id, name)
sql.rightJoin("test2", ["id", "name"]);
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
{Array|Object} options
When an array is passed in the a using clause is used to specify the columns to join on, of an object is passed in then it is the same as using an on clause;
Returns:
{SQL} this to allow chaining of query elements.

{SQL} rightOuterJoin(table, options)
Add a right outer join to another table
sql.rightOuterJoin("test2", {id : "id"});
//select * from test right outer join test2 on test.id=test2.id
sql.rightOuterJoin("test2", ["id", "name"]);
//select * from test right outer join test2 using (id, name);
Parameters:
{String|SQL} table
the table or SQL clause that specifies the joining table.
{Array|Object} options
When an array is passed in the a using clause is used to specify the columns to join on, of an object is passed in then it is the same as using an on clause;
Returns:
{SQL} this to allow chaining of query elements.

<static> {comb.Promise} SQL.save(table, object, db)
Perform a batch insert into a table the objects.
Parameters:
{String} table
the name of the table
{Object} object
the values to insert into the table
{moose.adapters.client.Query|moose.adapters.client.TransactionQuery} db
the conneciton to the database.
Returns:
{comb.Promise} called back with results or the error call back is called with an error.

<static> {comb.Promise} SQL.schema(tableName, db)
Retrieve and create a moose.Table from a schema stored in the database.
Parameters:
{String} tableName
name of the table
{moose.adapters.client.Query|moose.adapters.client.TransactionQuery} db
the conneciton to the database.
Returns:
{comb.Promise} called back with moose.Table or the error call back is called with an error.

{SQL} select(columns, options)
Use to return particular columns from a query, i.e. select clause in sql.
var sql = new SQL("test", db);

//select a, b, c from testTable;
sql.select(["a", "b", "c"]);
//select a from testTable;
sql.select("a");
//select a from test where x = 1 and y >=1 and y <= 10
sql.select("a", {x : 1, y : {between : [1,10]}});
Parameters:
{String|Array} columns
the columns to select
{Object} options
query SQL#find
Returns:
{SQL} this to allow chaining of query elements.

{SQL} std(options)
Helper to add a std clause.
//select std(name) as name_std from test
sql.std("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a std is added for that particular columns, an array adds a std for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} stdDev(options)
Helper to add a std dev clause.
//select stddev(name) as name_stddev from test
sql.stdDev("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a std dev is added for that particular columns, an array adds a std dev for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} stdDevPop(options)
Helper to add a std dev clause.
//select stddev_pop(name) as name_stddev_pop from test
sql.stdDevPop("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a std dev pop is added for that particular columns, an array adds a std dev pop for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} stdDevSamp(options)
Helper to add a std dev samp clause.
//select stddev_samp(name) as name_stddev_samp from test
sql.stdDevSamp("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a std dev samp is added for that particular columns, an array adds a std dev samp for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} sum(options)
Helper to add a sum clause.
//select sum(name) as name_sum from test
sql.sum("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a sum is added for that particular columns, an array adds a sum for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

<static> SQL.unique()
Create a unique constraint statement

See your client adpater for parameters!


{SQL} update(values, query)
Signify this SQL instance as an update statement.

Cannot be used in combination with remove, or find queries.

//update test set x=1
sql.update({x : 1});
//update test set x=1 where x >= 1 and x <= 5
sql.update({x : 1}, {x : {between : [1,5]}});
//update test set x=1 where x >= 1 and x <= 5
sql.update({x : 1}).where({x : {between : [1,5]}});
//update test set x=1 where x >= 1 and x <= 5
sql.update({x : 1}).find({x : {between : [1,5]}});
//update test inner join test2 on test.flag=test2.false set x=1
sql.update({x : 1}).join("test2", {flag : false});
Parameters:
{Object} values
key value pairs of columns, and values to update.
{Object} query Optional
optional query to allow limiting of rows to update SQL#where
Returns:
{SQL} this to allow chaining of query elements.

{SQL} variance(options)
Helper to add a variance clause.
//select variance(name) as name_variance from test
sql.variance("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a variance is added for that particular columns, an array adds a variance for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} varPop(options)
Helper to add a var pop clause.
//select var_pop(name) as name_var_pop from test
sql.varPop("name");
Parameters:
{String|Array} options Optional, Default: "*"
if a string is supplied then a var pop is added for that particular columns, an array adds a var pop for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} varSamp(options, options)
Helper to add a var samp clause.
//select var_samp(name) as name_var_samp from test
sql.varSamp("name");
Parameters:
options
{String|Array} options Optional, Default: "*"
if a string is supplied then a var samp is added for that particular columns, an array adds a var samp for each column in the array.
Returns:
{SQL} this to allow chaining of query elements.

{SQL} where(options)
Set the where clause of the query. This is different fron find in that it can be used with updates, and deletions.
QUERYING

var sql = new SQL("test", db);

//select * from test where id = 1
sql.where({id : 1});
//select * from test where id in (1,2,3,4,5)
sql.where({id : [1,2,3,4,5]});
//select * from test where x != 0
sql.where({x : {neq : 0}});
//select distinct * from test where id = 1
sql.where({id : 1}).distinct();
//select * from test where a >= 'b' limit 1
sql.where({a : {gte : "b"}}).limit(1);
//select * from test where flag is unknown
sql.where({flag : {is : "unknown"}});
//select * from test where flag is not unknown
sql.where({flag : {isNot : "unknown"}});
//select * from test where flag is false and flag is not unknown and anotherFlag is null and yetAnotherFlag is not null
sql.where({flag : {is : false}, flag2 : {isNot : "unknown"}, anotherFlag : {isNull : true}, yetAnotherFlag : {isNotNull : true}});
//select * from test where firstName like 'bob' and lastName not like 'henry'
sql.where({firstName : {like : 'bob'}, lastName : {notLike : "henry"}});
//select * from test where firstName like 'bob' and lastName not like 'henry'
sql.where({firstName : {like : 'bob'}, lastName : {notLike : "henry"}});
UPDATES

//update test set x=1 where x >= 1 and x <= 5
sql.update({x : 1}).where({x : {between : [1,5]}});
DELETIONS

//delete from test where x >= 1 and x <= 5
sql.remove().where({x : {between : [1,5]}});
Parameters:
{Object} options
See SQL#find
Returns:
{SQL} this to allow chaining of query elements.

Documentation generated by JsDoc Toolkit 2.4.0 on Sat Jun 11 2011 03:16:40 GMT-0500 (CDT)