Comments (7)
Say I have this:
BaseDialect = require('gesundheit/lib/dialects').base
class @MSAccessDialect extends BaseDialect
renderLimit: (node) ->
'hello hello'
and then in dialects.js
I add a console.log
:
Visitor.prototype.compile = function(node, allowOverride) {
var custom, name, string, _ref1, _ref2;
if (allowOverride == null) {
allowOverride = true;
}
this.path.push(node);
name = node != null ? (_ref1 = node.__proto__) != null ? (_ref2 = _ref1.constructor) != null ? _ref2.name : void 0 : void 0 : void 0;
console.log (name, this.dialect.renderLimit) // < ----------------------------
if (allowOverride && name && (custom = this.dialect['render' + name])) {
string = custom.call(this, node);
} else {
string = node.compile(this, this.path);
}
this.path.pop(node);
return string;
};
This is what is printed:
SelectQuery function (node) {
return 'hello hello';
}
Select undefined
SelectColumnSet undefined
RelationSet undefined
Relation undefined
Join undefined
JoinType undefined
ValueNode undefined
Relation undefined
ValueNode undefined
And undefined
Binary undefined
Column undefined
Relation undefined
Field undefined
Column undefined
Relation undefined
Field undefined
Where undefined
TextNode undefined
Limit undefined
this.dialect
is being reset to MySQLDialect
.
I should also mention that I am using it like this:
{MSAccessDialect} = require 'config/initializers/gesundheit/dialects'
dialect = new MSAccessDialect
q = dialect.compile(q)[0]
// q is sent to database connection for running...
Here is the stack trace from new Visitor()
. Seems I shouldn't be using a dialect to compile, rather an engine.
at new Visitor (xxx/node_modules/gesundheit/lib/dialects.js:102:15)
at MySQLDialect.BaseDialect.compile (xxx/node_modules/gesundheit/lib/dialects.js:30:15)
at Engine.compile (xxx/node_modules/gesundheit/lib/engine.js:98:25)
at SelectQuery.module.exports.BaseQuery.compile (xxx/node_modules/gesundheit/lib/queries/base.js:106:24)
at Visitor.compile (xxx/node_modules/gesundheit/lib/dialects.js:120:23)
at MSAccessDialect.BaseDialect.compile (xxx/node_modules/gesundheit/lib/dialects.js:31:20)
from gesundheit.
Ok so a workaround I came to was:
{MSAccessDialect} = require 'config/initializers/gesundheit/dialects'
dialect = new MSAccessDialect
fakePool =
begin: (cb) ->
if cb then process.nextTick(cb.bind(null, engine))
engine
query: (sql, params, cb) ->
throw new Error("Cannot query with fakeEngine. Do `gesundheit.defaultEngine = gesundheit.engine(url)` before querying")
close: ->
engine = new Engine null, null, fakePool, dialect
q = engine.compile(q)[0]
But unfortunately Engine
is not exported, only the factory Engine#create
which does not support custom 3rd party engines.
Engine#create
should take another parameter to specify a custom dialectType
class.
from gesundheit.
Ok the problem was that I was using:
g = require 'gesundheit'
db = g.engine('mysql://localhost/test')
g.defaultEngine = db
...and then building the query using g.select(...)
.
It seems like with this approach queries may be too tightly bound to the engine. It would be good to be able to create queries and then run them on multiple engines when required.
I'm not sure its a real problem though - just too me a while to track down. And I do have a unique use case.
from gesundheit.
You can rebind queries with query.bind(engine)
but this is not documented or actually supported (e.g. I may remove it in the future).
-Stephen
On 10 November, 2013 at 10:33:51 PM, Vaughan Rouesnel ([email protected]) wrote:
Ok the problem was that I was using:
g = require 'gesundheit'
db = g.engine('mysql://localhost/test')
g.defaultEngine = db
...and then building the query using g.select(...).
It seems like with this approach queries may be too tightly bound to the engine. It would be good to be able to create queries and then run them on multiple engines when required.
—
Reply to this email directly or view it on GitHub.
from gesundheit.
Cheers. From the original question: What is the best way to change the order of the Limit
node?
from gesundheit.
I think I found it - just have to modify _nodeOrder
.
renderSelect: (node) ->
console.log node.constructor
node.constructor._nodeOrder = [
'limit',
'distinct',
'projections',
'relations',
'where',
'groupBy',
'having',
'orderBy',
'offset'
]
node.compile this, true
from gesundheit.
hm, that works, but it's rather ugly. I would definitely be interested in a patch that moves the ordering of Statement child-nodes into BaseDialect. It really does make more sense for the ordering of the output to be controlled by the dialect than the node itself.
from gesundheit.
Related Issues (20)
- Deprecated `project` still found in documentation
- Incorrect column/keyword escaping characters for MySQL HOT 3
- any-db pooling HOT 1
- Feature: fields include table name HOT 6
- Example on IS NOT TRUE HOT 3
- Bug on condition OR/AND
- A better joining? HOT 4
- gesundheit package.json is still picking up [email protected]
- AnyDB link in README is broken
- Error handling for where clause with undefined predicate HOT 3
- Docs appear broken HOT 4
- update for any-db 2.0 HOT 8
- GroupBy() an aliased column HOT 1
- Postgres JSON API
- SQL Function in Order HOT 1
- Run against multiple databases in one process HOT 2
- allow exists/notExists as a field HOT 2
- allow subselects in joins HOT 1
- add 'after' parameter to .join() HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gesundheit.