Skip to content

Commit

Permalink
Fix for mappings to work correctly in modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed May 5, 2016
1 parent 9efbe5b commit 7502394
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 39 deletions.
11 changes: 8 additions & 3 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ component {
this.author = 'Eric Peterson';
this.webURL = 'https://github.com/elpete/quick';
this.description = 'Query builder for the rest of us';
this.version = '1.0.0';
this.autoMapModels = false;
this.version = '0.1.0';
this.autoMapModels = true;
this.cfmapping = 'Quick';

function configure() {}
function configure() {
binder.map('Grammar@Quick')
// make this default grammar a setting
.to('#moduleMapping#.models.Query.Grammars.OracleGrammar');
}

}
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quick",
"version": "1.0.0",
"version": "0.1.0",
"author": "Eric Peterson",
"homepage": "https://github.com/elpete/quick",
"documentation": "https://github.com/elpete/quick",
Expand Down
6 changes: 3 additions & 3 deletions models/Query/Builder.cfc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
component displayname='Builder' {

property name='grammar' inject='Grammar@Quick';

property name='distinct' type='boolean' default='false';
property name='columns' type='array';
property name='from' type='string';
Expand All @@ -23,9 +25,7 @@ component displayname='Builder' {
"where" = []
};

public Builder function init(required Quick.Query.Grammars.Grammar grammar) {
variables.grammar = arguments.grammar;

public Builder function init() {
setDefaultValues();

return this;
Expand Down
3 changes: 0 additions & 3 deletions models/Query/Grammars/Grammar.cfc

This file was deleted.

3 changes: 3 additions & 0 deletions models/Query/Grammars/GrammarInterface.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface displayname='GrammarInterface' {
public string function compileSelect(required Quick.models.Query.Builder query);
}
12 changes: 6 additions & 6 deletions models/Query/Grammars/OracleGrammar.cfc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
component displayname='OracleGrammar' implements='Quick.Query.Grammars.Grammar' {
component displayname='OracleGrammar' implements='Quick.models.Query.Grammars.GrammarInterface' {

variables.selectComponents = [
'columns', 'from', 'wheres', 'joins'
];

public string function compileSelect(required Quick.Query.Builder query) {
public string function compileSelect(required Quick.models.Query.Builder query) {

var sql = [];

Expand All @@ -19,16 +19,16 @@ component displayname='OracleGrammar' implements='Quick.Query.Grammars.Grammar'
return concatenate(sql);
}

private string function compileColumns(required Quick.Query.Builder query, required array columns) {
private string function compileColumns(required Quick.models.Query.Builder query, required array columns) {
var select = query.getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
return select & ArrayToList(columns);
}

private string function compileFrom(required Quick.Query.Builder query, required string from) {
private string function compileFrom(required Quick.models.Query.Builder query, required string from) {
return 'FROM ' & from;
}

private string function compileJoins(required Quick.Query.Builder query, required array joins) {
private string function compileJoins(required Quick.models.Query.Builder query, required array joins) {
return arrayToList(arrayMap(arguments.joins, function(join) {
var clauses = arrayToList(arrayMap(join.getClauses(), function(clause, index) {
if (index == 1) {
Expand All @@ -41,7 +41,7 @@ component displayname='OracleGrammar' implements='Quick.Query.Grammars.Grammar'
}), ' ');
}

private string function compileWheres(required Quick.Query.Builder query, requierd array wheres) {
private string function compileWheres(required Quick.models.Query.Builder query, requierd array wheres) {
var whereStatements = ArrayMap(wheres, function(where, index) {
if (! isStruct(where)) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion tests/Application.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
component {
this.mappings["/tests"] = getDirectoryFromPath(getCurrentTemplatePath());
this.mappings["/Quick"] = expandPath("/models");
this.mappings["/Quick"] = expandPath("/");
}
4 changes: 2 additions & 2 deletions tests/specs/Query/Builder/BuilderCollaboratorsSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ component extends='testbox.system.BaseSpec' {
function run() {
describe('interaction with collaborators', function() {
beforeEach(function() {
variables.mockGrammar = getMockBox().createStub(implements = 'Quick.Query.Grammars.Grammar');
variables.query = new Quick.Query.Builder(variables.mockGrammar);
variables.mockGrammar = getMockBox().createStub(implements = 'Quick.models.Query.Grammars.GrammarInterface');
variables.query = new Quick.models.Query.Builder(variables.mockGrammar);
});

describe('interaction with grammar', function() {
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/Query/Builder/BuilderJoinSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ component extends='testbox.system.BaseSpec' {
function run() {
describe('join methods', function() {
beforeEach(function() {
variables.mockGrammar = getMockBox().createStub(implements = 'Quick.Query.Grammars.Grammar');
variables.query = new Quick.Query.Builder(variables.mockGrammar);
variables.mockGrammar = getMockBox().createStub(implements = 'Quick.models.Query.Grammars.GrammarInterface');
variables.query = new Quick.models.Query.Builder(variables.mockGrammar);
});

it('does a simple inner join', function() {
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/Query/Builder/BuilderSelectSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ component extends='testbox.system.BaseSpec' {
function run() {
describe('select methods', function() {
beforeEach(function() {
variables.mockGrammar = getMockBox().createStub(implements = 'Quick.Query.Grammars.Grammar');
variables.query = new Quick.Query.Builder(variables.mockGrammar);
variables.mockGrammar = getMockBox().createStub(implements = 'Quick.models.Query.Grammars.GrammarInterface');
variables.query = new Quick.models.Query.Builder(variables.mockGrammar);
});

describe('select()', function() {
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/Query/Builder/BuilderWhereSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ component extends='testbox.system.BaseSpec' {
function run() {
describe('where methods', function() {
beforeEach(function() {
variables.mockGrammar = getMockBox().createStub(implements = 'Quick.Query.Grammars.Grammar');
variables.query = new Quick.Query.Builder(variables.mockGrammar);
variables.mockGrammar = getMockBox().createStub(implements = 'Quick.models.Query.Grammars.GrammarInterface');
variables.query = new Quick.models.Query.Builder(variables.mockGrammar);
});

it('defaults to empty', function() {
Expand Down
16 changes: 8 additions & 8 deletions tests/specs/Query/Builder/JoinClauseSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ component extends='testbox.system.BaseSpec' {
function run() {
describe('initialization', function() {
it('requires a type and a table', function() {
expect(function() { new Quick.Query.JoinClause(); }).toThrow();
expect(function() { new Quick.Query.JoinClause('inner'); }).toThrow();
expect(function() { new Quick.Query.JoinClause('inner', 'sometable'); }).notToThrow();
expect(function() { new Quick.models.Query.JoinClause(); }).toThrow();
expect(function() { new Quick.models.Query.JoinClause('inner'); }).toThrow();
expect(function() { new Quick.models.Query.JoinClause('inner', 'sometable'); }).notToThrow();
});

it('validates the type is a valid sql join type', function() {
expect(function() { new Quick.Query.JoinClause('gibberish', 'sometable') }).toThrow();
expect(function() { new Quick.Query.JoinClause('left typo', 'sometable') }).toThrow();
expect(function() { new Quick.Query.JoinClause('left', 'sometable') }).notToThrow();
expect(function() { new Quick.Query.JoinClause('left outer', 'sometable') }).notToThrow();
expect(function() { new Quick.models.Query.JoinClause('gibberish', 'sometable') }).toThrow();
expect(function() { new Quick.models.Query.JoinClause('left typo', 'sometable') }).toThrow();
expect(function() { new Quick.models.Query.JoinClause('left', 'sometable') }).notToThrow();
expect(function() { new Quick.models.Query.JoinClause('left outer', 'sometable') }).notToThrow();
});
});

describe('adding join conditions', function() {
beforeEach(function() {
variables.join = new Quick.Query.JoinClause('inner', 'second');
variables.join = new Quick.models.Query.JoinClause('inner', 'second');
});

afterEach(function() {
Expand Down
12 changes: 6 additions & 6 deletions tests/specs/Query/Grammar/GrammarCompileSQLSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ component extends='testbox.system.BaseSpec' {
function run() {
describe('compileSelect', function() {
beforeEach(function() {
variables.grammar = new Quick.Query.Grammars.OracleGrammar();
variables.mockQuery = getMockBox().createMock('Quick.Query.Builder');
variables.grammar = new Quick.models.Query.Grammars.OracleGrammar();
variables.mockQuery = getMockBox().createMock('Quick.models.Query.Builder');
mockQuery.$('getDistinct', false);
mockQuery.$('getColumns', ['*']);
mockQuery.$('getFrom', 'sometable');
Expand Down Expand Up @@ -49,7 +49,7 @@ component extends='testbox.system.BaseSpec' {

describe('compiling joins', function() {
it('adds a single join', function() {
var mockJoin = getMockBox().createMock('Quick.Query.JoinClause');
var mockJoin = getMockBox().createMock('Quick.models.Query.JoinClause');
mockJoin.$('getType', 'inner');
mockJoin.$('getTable', 'othertable');
mockJoin.$('getClauses', [{
Expand All @@ -66,7 +66,7 @@ component extends='testbox.system.BaseSpec' {
});

it('adds multiple joins', function() {
var mockJoinOne = getMockBox().createMock('Quick.Query.JoinClause');
var mockJoinOne = getMockBox().createMock('Quick.models.Query.JoinClause');
mockJoinOne.$('getType', 'inner');
mockJoinOne.$('getTable', 'othertable');
mockJoinOne.$('getClauses', [{
Expand All @@ -75,7 +75,7 @@ component extends='testbox.system.BaseSpec' {
second = 'othertable.sometable_id',
combinator = 'and'
}]);
var mockJoinTwo = getMockBox().createMock('Quick.Query.JoinClause');
var mockJoinTwo = getMockBox().createMock('Quick.models.Query.JoinClause');
mockJoinTwo.$('getType', 'left');
mockJoinTwo.$('getTable', 'anothertable');
mockJoinTwo.$('getClauses', [{
Expand All @@ -92,7 +92,7 @@ component extends='testbox.system.BaseSpec' {
});

it('adds all the clauses in a join', function() {
var mockJoin = getMockBox().createMock('Quick.Query.JoinClause');
var mockJoin = getMockBox().createMock('Quick.models.Query.JoinClause');
mockJoin.$('getType', 'inner');
mockJoin.$('getTable', 'othertable');
mockJoin.$('getClauses', [
Expand Down

0 comments on commit 7502394

Please sign in to comment.