<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Minimal example of using Lovefield</title>
<script src="../components/lovefield/dist/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.distinct(item.id, item.description, item.deadline, item.done)).from(item).where(item.done.eq(false)).exec();
}).then(function(results) {
results.forEach(function(row) {
console.log(row);
});
});
</script>
</body>
</html>
I have modified the basic example a little to select every individual column in the lf.fn.distinct function. The function appears to be returning only the values in the first column passed into the lf.fn.distinct function(item.id) and not the other columns. Is there a way to use distinct that will return all the column values?