Skip to content

Commit

Permalink
feat(demo): storage-client
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Nov 16, 2022
1 parent 2da68ba commit e19abc4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {random} from '@alwatr/math';
import {AlwatrStorage} from '@alwatr/storage';
import {AlwatrStorageClient} from '@alwatr/storage-client';

import type {DocumentObject} from '@alwatr/storage';

Expand All @@ -10,14 +10,14 @@ interface User extends DocumentObject {
token: string;
}

const db = new AlwatrStorage<User>({
const db = new AlwatrStorageClient<User>({
name: 'junk-data',
path: 'db',
saveBeautiful: false,
debug: false,
server: 'http://localhost:80',
token: 'alwatr_110_313',
});

for (let i = 0; i < 100_000; i++) {
console.time('get item');
for (let i = 0; i < 100; i++) {
db.set({
_id: random.string(4, 16),
_updatedBy: 'demo' + i,
Expand All @@ -27,11 +27,6 @@ for (let i = 0; i < 100_000; i++) {
token: random.string(16),
});
}

console.time('get item');
const item = db.get('_last');
console.timeEnd('get item');
console.dir(item);

db.forceSave();
console.log('done');
16 changes: 10 additions & 6 deletions demo/storage/index.ts → demo/storage-client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AlwatrStorage} from '@alwatr/storage';
import {AlwatrStorageClient} from '@alwatr/storage-client';

import type {DocumentObject} from '@alwatr/storage';

Expand All @@ -9,16 +9,15 @@ interface User extends DocumentObject {
token?: string;
}

const db = new AlwatrStorage<User>({
const db = new AlwatrStorageClient<User>({
name: 'user-list',
path: 'db',
saveBeautiful: true,
debug: true,
server: 'http://localhost:80',
token: 'alwatr_110_313',
});

console.log('db loaded and ready to access.');

let ali = db.get('alimd');
let ali = await db.get('alimd');

if (ali == null) {
console.log('ali not found');
Expand Down Expand Up @@ -54,3 +53,8 @@ db.set({
email: 'Fatemeh@mihandoost.com',
token: Math.random().toString(36).substring(2, 15),
});

console.log(await db.getAll());
console.log(await db.keys());
console.log(await db.delete('ali'));
console.log(await db.delete('alimd'));
2 changes: 1 addition & 1 deletion demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"path": "../packages/core/i18n"},
{"path": "../packages/core/math"},
{"path": "../packages/core/element"},
{"path": "../packages/core/storage"},
{"path": "../packages/core/storage-client"},
{"path": "../packages/core/token"}
],
"exclude": ["*.d.ts", "node_modules"]
Expand Down

0 comments on commit e19abc4

Please sign in to comment.