firemail

标题: db---indexdb [打印本页]

作者: hechengjin    时间: 2015-10-22 10:58
标题: db---indexdb
本帖最后由 hechengjin 于 2015-10-22 17:10 编辑

https://github.com/dfahlander/Dexie.js

1.数据库版本兼容
get db() {
    let db = new Dexie(contactsStorageDBName);


    db.version(storage.version).stores({
      folders: "++id,name,folderId,description",
      contacts: "++id,groupId,displayName,priorityDisplay,firstName,lastName,*email,*phone,*im,sex,*address,company,department,title,contactsId,notes,[firstName+lastName],pinYin"
    } );

  /*  db.version(2).stores({
      folders: "++id,name,description",
      contacts: "++id,groupId,displayName,firstName,lastName,*email"
    } );

    db.version(1).stores({
        folders: "++id,name,description",
      contacts: "++id,groupId,displayName,firstName,lastName"
    });
*/
    db.open();
    return db;
  },
2.观察数据库变化
db.on('changes', function (changes) {
        changes.forEach(function (change) {
          switch (change.type) {
            case 1: // CREATED
            {
              console.log('Table '+change.table+' An object was created: ' + JSON.stringify(change.obj));
            }

                break;
            case 2: // UPDATED
                console.log('An object with key ' + change.key + ' was updated with modifications: ' + JSON.stringify(change.mods));
                break;
            case 3: // DELETED
                console.log('An object was deleted: ' + JSON.stringify(change.oldObj));
                break;
          };
      });
    });

    db.mailgroups.hook("creating", function (primKey, obj, trans) {

      if (obj.hasOwnProperty("groupId")) {
        // "message" property is being updated
        if (typeof obj.groupId == 'string')
            console.log(obj.groupId+' 1111111111');
        else
            console.log(obj.groupId+' 2222222');
      }
    });







欢迎光临 firemail (http://firemail.wang:8088/) Powered by Discuz! X3