Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Commit

Permalink
Improved Block.exposedMethods() logic.
Browse files Browse the repository at this point in the history
Updated README with custom query example.

Bumped version to 1.1
  • Loading branch information
hiddentao committed Mar 27, 2013
1 parent 4afea7b commit a0cefe8
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 146 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
# Changelog for [squel](https://github.com/hiddentao/squel)


## 27 Mar 2013 (1.1)
* Squel can now be customized to include proprietary commands and queries.
* AMD support added.


## 4 Jan 2013 (1.0.6)
* Squel can now be told to auto-quote table and field names.

Expand Down
72 changes: 68 additions & 4 deletions README.md
Expand Up @@ -2,15 +2,15 @@

[![Build Status](https://secure.travis-ci.org/hiddentao/squel.png)](http://travis-ci.org/hiddentao/squel)

A simple, well tested SQL query string builder for Javascript.
A flexible and powerful SQL query string builder for Javascript.

## Features

* Works in node.js and in the browser.
* Supports the construction of all standard SQL queries: SELECT, UPDATE, INSERT and DELETE.
* Supports the standard SQL queries: SELECT, UPDATE, INSERT and DELETE.
* Can be customized to support non-standard queries.
* Uses method chaining for ease of use.
* Well tested (~200 tests).
* Small: ~3 KB when minified and gzipped.
* Well tested (~230 tests).

## Installation

Expand Down Expand Up @@ -142,6 +142,70 @@ There is also an expression builder which allows you to build complex expression
.join( "test2", null, squel.expr().and("test.id = test2.id") )
.where( squel.expr().or("test = 3").or("test = 4") )

**Custom queries**

Squel allows you to override the built-in query builders with your own as well as create your own types of queries:

// ------------------------------------------------------
// Setup the PRAGMA query builder
// ------------------------------------------------------
var util = require('util'); // to use util.inherits() from node.js

var CommandBlock = function() {};
util.inherits(CommandBlock, squel.cls.Block);

CommandBlock.prototype.compress = function() {
this._command = 'compress';
};

CommandBlock.prototype.buildStr = function() {
return this._command.toUpperCase();
};


// generic parameter block
var ParamBlock = function() {};
util.inherits(ParamBlock, squel.cls.Block);

ParamBlock.prototype.param = function(p) {
this._p = p;
};

ParamBlock.prototype.buildStr = function() {
return this._p;
};


// pragma query builder
var PragmaQuery = function(options) {
var blocks = [
new squel.cls.StringBlock(options, 'PRAGMA'),
new CommandBlock(),
new ParamBlock()
];

squel.cls.QueryBuilder.call(this, options, blocks);
};
util.inherits(PragmaQuery, squel.cls.QueryBuilder);


// convenience method (we can override built-in squel methods this way too)
squel.pragma = function(options) {
return new PragmaQuery(options)
};


// ------------------------------------------------------
// Build a PRAGMA query
// ------------------------------------------------------

squel.pragma()
.compress()
.param('test')
.toString();

// 'PRAGMA COMPRESS test'


## Documentation

Expand Down
132 changes: 65 additions & 67 deletions docs/squel.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "squel",
"description": "SQL query string builder",
"version": "1.0.7",
"version": "1.1",
"author": "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
"contributors": [
"Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
Expand Down
49 changes: 6 additions & 43 deletions squel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0cefe8

Please sign in to comment.