mirror of
https://github.com/flynx/pWiki.git
synced 2025-11-01 03:20:08 +00:00
experimental journal done, still not used...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ac43d78333
commit
737b250361
@ -18,7 +18,7 @@ var index = require('../index')
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// XXX EXPERIMENTAL...
|
||||||
var JournalDB =
|
var JournalDB =
|
||||||
module.JournalDB =
|
module.JournalDB =
|
||||||
object.Constructor('JournalDB', {
|
object.Constructor('JournalDB', {
|
||||||
@ -75,21 +75,31 @@ object.Constructor('JournalDB', {
|
|||||||
req.onsuccess = function(evt){
|
req.onsuccess = function(evt){
|
||||||
that.__db = req.result } }) },
|
that.__db = req.result } }) },
|
||||||
|
|
||||||
// XXX
|
// XXX should these be props???
|
||||||
|
// XXX should these be cached???
|
||||||
get length(){ return async function(){
|
get length(){ return async function(){
|
||||||
return this.__promisify(
|
return this.__promisify(
|
||||||
(await this.db)
|
(await this.db)
|
||||||
.transaction('journal', 'readonly')
|
.transaction('journal', 'readonly')
|
||||||
.objectStore('journal')
|
.objectStore('journal')
|
||||||
.count()) }.call(this) },
|
.count()) }.call(this) },
|
||||||
|
get paths(){ return async function(){
|
||||||
|
return (await this.slice())
|
||||||
|
.map(function(elem){
|
||||||
|
return elem.path })
|
||||||
|
.unique() }.call(this) },
|
||||||
|
|
||||||
slice: async function(from, to){
|
// get entries by time...
|
||||||
|
slice: async function(from=0, to=Infinity){
|
||||||
return this.__promisify(
|
return this.__promisify(
|
||||||
(await this.db)
|
(await this.db)
|
||||||
.transaction('journal', 'readonly')
|
.transaction('journal', 'readonly')
|
||||||
.objectStore('journal')
|
.objectStore('journal')
|
||||||
.getAll(IDBKeyRange.lowerBound(from ?? 0, true))) },
|
.getAll(IDBKeyRange.bound(
|
||||||
|
from ?? 0,
|
||||||
|
to ?? Infinity,
|
||||||
|
true, true))) },
|
||||||
|
// get entries by path...
|
||||||
path: async function(path){
|
path: async function(path){
|
||||||
return this.__promisify(
|
return this.__promisify(
|
||||||
(await this.db)
|
(await this.db)
|
||||||
@ -98,13 +108,10 @@ object.Constructor('JournalDB', {
|
|||||||
.index('path')
|
.index('path')
|
||||||
.getAll(...arguments)) },
|
.getAll(...arguments)) },
|
||||||
|
|
||||||
get paths(){
|
//
|
||||||
},
|
// <journal-db>.add(<path>, <action>, ...)
|
||||||
|
// -> <promise>
|
||||||
// remove entries up to date...
|
//
|
||||||
trim: function(date){
|
|
||||||
// XXX
|
|
||||||
},
|
|
||||||
add: async function(path, action, ...data){
|
add: async function(path, action, ...data){
|
||||||
return this.__promisify(
|
return this.__promisify(
|
||||||
(await this.db)
|
(await this.db)
|
||||||
@ -120,10 +127,22 @@ object.Constructor('JournalDB', {
|
|||||||
data,
|
data,
|
||||||
})) },
|
})) },
|
||||||
|
|
||||||
|
// remove entries up to date...
|
||||||
|
trim: async function(to){
|
||||||
|
return this.__promisify(
|
||||||
|
(await this.db)
|
||||||
|
.transaction('journal', 'readwrite')
|
||||||
|
.objectStore('journal')
|
||||||
|
.delete(IDBKeyRange.upperBound(to ?? 0, true))) },
|
||||||
|
// clear journal...
|
||||||
clear: function(){
|
clear: function(){
|
||||||
indexedDB.deleteDatabase(this.id)
|
indexedDB.deleteDatabase(this.id)
|
||||||
delete this.__db },
|
delete this.__db },
|
||||||
|
|
||||||
|
//
|
||||||
|
// JournalDB(<id>)
|
||||||
|
// -> <journal-db>
|
||||||
|
//
|
||||||
__init__: function(id){
|
__init__: function(id){
|
||||||
var that = this
|
var that = this
|
||||||
this.id = id ?? this.id
|
this.id = id ?? this.id
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user