diff --git a/demo/engine/collection.ts b/demo/engine/collection.ts new file mode 100644 index 00000000..02f1dfca --- /dev/null +++ b/demo/engine/collection.ts @@ -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(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) { + // 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(); diff --git a/demo/engine/doc.ts b/demo/engine/doc.ts new file mode 100644 index 00000000..d8f8394f --- /dev/null +++ b/demo/engine/doc.ts @@ -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(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();