How to create relationships using the Indexed Database API of HTML 5?

3

Does anyone know how to relate data using Indexed Databases in HTML 5? I've seen many examples of how the API works, but in none of them have I seen data being related. For example, how would relationships 1: N ... 1: 1 ... N: N ...

    
asked by anonymous 18.09.2015 / 22:50

1 answer

0

I recommend using the Google lib for IndexedDB lovefield .

Example of use:

# pseudo código da query
SELECT * FROM photo
  INNER JOIN album
    ON photo.albumId = album.id
  WHERE album.id = '1'
// Usando o lovefield para executar a query com innerJoin
var schemaBuilder = lf.schema.create('albums', 1);

schemaBuilder.createTable('Album')
  .addColumn('id', lf.Type.INTEGER)
  .addColumn('title', lf.Type.STRING);

schemaBuilder.createTable('Photo')
  .addColumn('photoId', lf.Type.INTEGER)
  .addColumn('title', lf.Type.STRING)
  .addColumn('albumId', lf.Type.INTEGER);

schemaBuilder.connect().then(function(db) {
  var schema = db.getSchema();
  var p = schema.table('Photo');
  var a = schema.table('Album');

  db.select()
    .from(p)
    .innerJoin(a, p.albumId.eq(a.id))
    .where(a.id.eq(1))
    .exec();
});
    
10.11.2015 / 16:22