Merge pull request #5813 from basp/level-sublevel

new definition files for level-sublevel
This commit is contained in:
Horiuchi_H
2015-09-15 11:45:39 +09:00
2 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
/// <reference path="level-sublevel.d.ts" />
import levelup = require('levelup');
import sublevel = require('level-sublevel');
var db = sublevel(levelup('./tmp/sublevel-example'));
var sub = db.sublevel('stuff');
db.put('foo', 'bar', err => {});
sub.put('foo', 'bar', err => {});
db.pre((ch, add) => {
add({
key: ''+Date.now(),
value: ch.key,
type: 'put',
prefix: sub
})
});
var sub1 = db.sublevel('SUB_1');
var sub2 = db.sublevel('SUM_2');
sub1.batch([
{ key: 'key', value: 'Value', type: 'put' },
{ key: 'key', value: 'Value', type: 'put', prefix: sub2 }
], err => { if (err) throw err; });

24
level-sublevel/level-sublevel.d.ts vendored Normal file
View File

@@ -0,0 +1,24 @@
// Type definitions for level-sublevel
// Project: https://github.com/dominictarr/level-sublevel
// Definitions by: Bas Pennings <https://github.com/basp/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../levelup/levelup.d.ts" />
interface Hook {
(ch: any, add: (op: Batch|boolean) => void): void;
}
interface Batch {
prefix?: Sublevel;
}
interface Sublevel extends LevelUp {
sublevel(key: string): Sublevel;
pre(hook: Hook): Function;
}
declare module "level-sublevel" {
function sublevel(levelup: LevelUp): Sublevel;
export = sublevel;
}