-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {createLogger} from '@alwatr/logger'; | ||
import {AlwatrStore, type AlwatrDocumentRefrence} from '@alwatr/store-engine'; | ||
|
||
const logger = createLogger('AlwatrStoreDemo', true); | ||
logger.banner('AlwatrStoreDemo'); | ||
|
||
// Create a new storage instance | ||
const alwatrStore = new AlwatrStore({ | ||
pathPrefix: 'db', | ||
saveDebounce: 100, | ||
}); | ||
|
||
interface DocumentDataType { | ||
title: string; | ||
body: string; | ||
} | ||
|
||
async function quickstart() { | ||
// Obtain a document reference. | ||
|
||
const collectionPath = { | ||
id: 'post-list', | ||
region: 'public', | ||
}; | ||
|
||
logger.logProperty?.('collectionPath', collectionPath); | ||
|
||
logger.logProperty?.('stat(collPath)', alwatrStore.stat(collectionPath)); | ||
|
||
const collectionRef = alwatrStore.collection<DocumentDataType>(collectionPath); | ||
|
||
processDocument(collectionRef.document('post-1')); | ||
processDocument(collectionRef.document('post-2')); | ||
|
||
// Delete the document. | ||
alwatrStore.unloadCollection(collectionRef.collectionPath); | ||
logger.logOther('Unload the collection from ram'); | ||
} | ||
|
||
function processDocument(documentRef: AlwatrDocumentRefrence<DocumentDataType>) { | ||
// Enter new data into the document. | ||
let documentContext = documentRef.set({ | ||
title: 'Welcome to Alwatr Storage', | ||
body: 'Hello World', | ||
}); | ||
logger.logOther?.('Entered new data into the document', documentContext); | ||
|
||
// Update an existing document. | ||
documentContext = documentRef.update({ | ||
body: 'My first AlwatrStore app', | ||
}); | ||
logger.logOther?.('Updated an existing document', documentContext); | ||
|
||
// Read the document. | ||
documentContext = documentRef.get(); | ||
logger.logOther?.('Read the document', documentContext); | ||
} | ||
|
||
quickstart(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { AlwatrStoreDocument } from 'fs/promises'; | ||
|
||
import { createLogger } from '@alwatr/logger'; | ||
import {AlwatrStore} from '@alwatr/store-engine'; | ||
const logger = createLogger('AlwatrStoreDemo', true); | ||
logger.banner('AlwatrStoreDemo'); | ||
|
||
// Create a new storage instance | ||
const alwatrStore = new AlwatrStore({ | ||
pathPrefix: 'db', | ||
saveDebounce: 100, | ||
}); | ||
|
||
interface DocumentDataType { | ||
title: string; | ||
body: string; | ||
} | ||
|
||
async function quickstart() { | ||
// Obtain a document reference. | ||
|
||
const documentPath = { | ||
id: 'posts/intro-to-alwatr-store', | ||
region: 'public', | ||
}; | ||
|
||
logger.logProperty?.('documentPath', documentPath); | ||
|
||
logger.logProperty?.('stat(docPath)', alwatrStore.stat(documentPath)); | ||
|
||
const documentRef = alwatrStore.document<DocumentDataType>(documentPath); | ||
|
||
logger.logProperty?.('doc.stat', documentRef.stat()); | ||
|
||
// Enter new data into the document. | ||
let documentContext = documentRef.set({ | ||
title: 'Welcome to Alwatr Storage', | ||
body: 'Hello World', | ||
}); | ||
logger.logOther?.('Entered new data into the document', documentContext); | ||
|
||
// Update an existing document. | ||
documentContext = documentRef.update({ | ||
body: 'My first AlwatrStore app', | ||
}); | ||
logger.logOther?.('Updated an existing document', documentContext); | ||
|
||
// Read the document. | ||
documentContext = documentRef.get(); | ||
logger.logOther?.('Read the document', documentContext); | ||
|
||
// Delete the document. | ||
documentRef.deleteFile(); | ||
logger.logOther?.('Deleted the document'); | ||
|
||
// Delete the document. | ||
alwatrStore.unloadDocument(documentRef.documentPath); | ||
logger.logOther?.('Unload the document from ram'); | ||
} | ||
quickstart(); |