lovefield.min.js does not support aliases for aggregate fields...
johndimm opened this issue · 3 comments
... but lovefield.js does.
The problem can be seen in the quick start todo demo. Replace the last statement with this:
return db.insertOrReplace().into(item).values([row]).exec();
}).then(function() {
return todoDb.select(
lf.fn.count().as('count of rows')
).from(item).where(item.done.eq(false)).exec();
}).then(function(results) {
results.forEach(function(row) {
console.log(row['count of rows']);
});
That works with lovefield.js (console log shows the correct count of 1), but fails on lovefield.min.js:
lovefield.min.js:28 Uncaught TypeError: lf.fn.count(...).as is not a function
Thanks for the report!
Given that @export annotation is used at
lovefield/lib/aggregated_column.js
Line 101 in 6e6cc7c
as()
when minify-ing, but apparently this is not the case. Need to investigate further, and potentially build a minimal repro against the compiler.I am not able to reproduce the problem. Seems to work fine for me with lovefield.min.js. See complete example below.
var schemaBuilder = lf.schema.create('todo', 1);
schemaBuilder.createTable('Item').
addColumn('id', lf.Type.INTEGER).
addColumn('description', lf.Type.STRING).
addColumn('deadline', lf.Type.DATE_TIME).
addColumn('done', lf.Type.BOOLEAN).
addPrimaryKey(['id']).
addIndex('idxDeadline', ['deadline'], false, lf.Order.DESC);
var todoDb;
var item;
schemaBuilder.connect().then(function(db) {
todoDb = db;
item = db.getSchema().table('Item');
var row = item.createRow({
'id': 1,
'description': 'Get a cup of coffee',
'deadline': new Date(),
'done': false
});
return db.insertOrReplace().into(item).values([row]).exec();
}).then(function() {
return todoDb.select(
lf.fn.count(item.id).as('count of rows')
).from(item).where(item.done.eq(false)).exec();
}).then(function(results) {
console.log(JSON.stringify(results));
});
Which prints the following in the devtools console
[{"count of rows":1}]
Which version of Lovefield are you using? I tried both the master branch, as well the 2.1.12 and both work fine.