<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Minimal example of using Lovefield</title>
<script src="lib/lovefield.min.js"></script>
</head>
<body>
<script>
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().as('count of rows')
// lf.fn.count()
).from(item).where(item.done.eq(false)).exec();
}).then(function(results) {
results.forEach(function(row) {
// console.log(row['description'], 'before', row['deadline']);
console.log(row['COUNT(*)']);
});
});
</script>
</body>
</html>
Since there is a test for count, I modified the quick start example to check.The following produces the error:lovefield.min.js:28 Uncaught TypeError: lf.fn.count(...).as is not a functionComment out the line with "as" and uncomment the one below it to remove the error and get the count of 1 in the console.Maybe my lovefield.min.js is bad?
Woo hoo! That did it. No problem when using lovefield.js instead of lovefield.min.js.