Skip to content

diasbruno/idbjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

idbjs

A functional approach to work with IndexDB.

It uses heavily data.task to provide a better promise composition.

Api

Configuration

const configDB = {
  name: "test",
  version: 24
};

withDB(config, storeT, queryT)

Perform a query using a store on the config database.

idb.withDB(
  configDB,
  idb.storeRW('contacts'),
  idb.selectWhere('name', 'eman')
).fork(
  err => {
	console.log("error", err);
  },
  succ => {
	console.log("success", succ.results);
  }
);

selectAll() -> Task

idb.withDB(
  configDB,
  idb.storeRO('contacts'),
  idb.selectAll()
).fork(
  err => {
	console.log("error", err);
  },
  succ => {
	console.log("success", succ.results);
  }
);

selectWhere(key, value) -> Task

idb.withDB(
  configDB,
  idb.storeRO('contacts'),
  idb.selectWhere('name', 'eman')
).fork(
  err => {
	console.log("error", err);
  },
  succ => {
	console.log("success", succ.results);
  }
);

insert(item) -> Task

idb.withDB(
  configDB,
  idb.storeRW('contacts'),
  idb.insert({ name: 'eman' })
).fork(
  err => {
	console.log("error", err);
  },
  succ => {
	console.log("success", succ.results);
  }
);

update(item) -> Task

idb.withDB(
  configDB,
  idb.storeRW('contacts'),
  idb.update({ id: 3, name: 'eman' })
).fork(
  err => {
	console.log("error", err);
  },
  succ => {
	console.log("success", succ.results);
  }
);

remove(item) -> Task

idb.withDB(
  configDB,
  idb.storeRW('contacts'),
  idb.update({ id: 3, name: 'eman' })
).fork(
  err => {
	console.log("error", err);
  },
  succ => {
	console.log("success", succ.results);
  }
);

License

See license.md.