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

Commit

Permalink
Refactored squel query builders to use Blocks - so that query buildin…
Browse files Browse the repository at this point in the history
…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
hiddentao committed Mar 27, 2013
1 parent baa7855 commit f60e5d1
Show file tree
Hide file tree
Showing 15 changed files with 2,872 additions and 1,914 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
660 changes: 386 additions & 274 deletions docs/squel.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit f60e5d1

Please sign in to comment.