Permalink
Browse files

Refactored squel query builders to use Blocks - so that query buildin…

…g can be better customized. This also allows one to create new builders for custom query types.

Added AMD support.

Bumped to version 1.1

----

Squashed commit of the following:

commit a0cefe8
Author: Ramesh Nair <ram@hiddentao.com>
Date:   Wed Mar 27 12:07:04 2013 +0800

    Improved Block.exposedMethods() logic.

    Updated README with custom query example.

    Bumped version to 1.1

commit 4afea7b
Author: Ramesh Nair <ram@hiddentao.com>
Date:   Wed Mar 27 11:09:31 2013 +0800

    Added custom block and query builder tests.

    Simplified Block code a little bit.

    All tests now passing.

commit e7590ac
Author: Ramesh Nair <ram@hiddentao.com>
Date:   Tue Mar 26 18:34:07 2013 +0800

    Updated all origial tests. All tests now passing.

commit fcca5cc
Author: Ramesh Nair <ram@hiddentao.com>
Date:   Tue Mar 26 13:55:35 2013 +0800

    Tests for base classes updated.

    Todo: tests for newly refactored query builders.

    Todo: tests to ensure that customised query builders and custom blocks work fine.

commit cd5475f
Author: Ramesh Nair <ram@hiddentao.com>
Date:   Mon Mar 25 22:24:41 2013 +0800

    Completed tests for all Blocks.

    Todo: tests for Builder and QueryBuilder classes as well as newly refactored query builders.

    Todo: tests to ensure that customised query builders and custom blocks work fine.

commit 77be046
Author: Ramesh Nair <ram@hiddentao.com>
Date:   Mon Mar 25 13:47:23 2013 +0800

    Refactored query builders to use 'building blocks'.

    Added AMD compatiblity.

    Todo: Refactor and update tests.
  • Loading branch information...
1 parent baa7855 commit f60e5d1c77ccef61c95803ebe9c8035dddfff2d1 @hiddentao committed Mar 27, 2013
Showing with 2,872 additions and 1,914 deletions.
  1. +5 −0 CHANGELOG.md
  2. +68 −4 README.md
  3. +386 −274 docs/squel.html
  4. +1 −1 package.json
  5. +671 −485 squel.js
  6. +1 −1 squel.min.js
  7. 0 src/blocks.coffee
  8. +551 −418 src/squel.coffee
  9. +100 −286 test/baseclasses.test.coffee
  10. +949 −0 test/blocks.test.coffee
  11. +111 −0 test/custom.test.coffee
  12. +6 −72 test/delete.test.coffee
  13. +7 −71 test/insert.test.coffee
  14. +6 −192 test/select.test.coffee
  15. +10 −110 test/update.test.coffee
View
@@ -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.
View
@@ -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
@@ -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
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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/)",
Oops, something went wrong.

0 comments on commit f60e5d1

Please sign in to comment.