@tekbox/node-storage
NodeStorage provides an interface to save all classes that extends StorageNode. Any storage backend that is implemented by @tekbox/unified-storage can be used. #### Usage
Last updated 3 years ago by r1co .
Original npm · Tarball · package.json
$ cnpm install @tekbox/node-storage 
SYNC missed versions from official npm registry.

@tekbox/node-storage

NodeStorage provides an interface to save all classes that extends StorageNode. Any storage backend that is implemented by @tekbox/unified-storage can be used.

Usage

Available methods:

export interface INodeHandler {
    saveNode<T extends INode>(node: T): ThenPromise<T>;

    getNode<T extends INode>(db: T, id: string, dbName?: string): ThenPromise<T>;

    deleteNode(node: INode, dbName?: string): ThenPromise<boolean>;

    getAllNodes<T extends INode>(type: T, dbName?: string): ThenPromise<T[]>;

    dumpAll(): ThenPromise<string>;
}

Usage:

export class TestNode extends StorageNode {
    public name: string;

    constructor(id?: string, name?: string) {
        super();
        this.id = id != null ? id : "";
        this.name = name != null ? name : "";
    }

}

export class TestHandler extends AbstractStorageHandler {
    getStorageAdapter(storageName: string): ThenPromise<UnifiedStorage> {
        return new ThenPromise<UnifiedStorage>(((resolve, reject) => {
            if (!this.storageAdapters.has(storageName)) {
                const us = new UnifiedStorage("test", new FilesystemStorageAdapter("./test", "testdata"));
                us.name = storageName;
                this.storageAdapters.set(storageName, us);
            }
            const adapter = this.storageAdapters.get(storageName);
            resolve(adapter);
        }));
    }

}
NodeHandlerStatic.Setup(new NodeHandler(new TestHandler()));

const nodeStorage = NodeHandlerStatic.GetInstance();

nodeStorage.getNode(new TestNode(), "node-id").then((node: TestNode) => {
    console.log(node);
}).catch((err) => {
    console.log(err);
});

Current Tags

  • 0.0.5                                ...           latest (3 years ago)

4 Versions

  • 0.0.5                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 5
Dependencies (2)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |