This package represent a table data structure with indexing and sorting on columns.
- Allows adding multiple columns.
- Columns values can be different from their indexed values.
- Allows sorting
- Provides Mapper and Generator Interface for pagination.
- Currently provides in memory implementation, in future release for pg implementation
import { MemoryICD } from "../dist/src/index.js";
const columnsToIndex = [0, 1]; // This are index numbers of the columns that will be indexed
const icd = new MemoryICD(columnsToIndex);
const rows = [
[{ IndexValue: "Johnny", Data: "John" }, { IndexValue: "D", Data: "Doe" }, 30],
[{ IndexValue: "Jane", Data: "Janet" }, { IndexValue: "D", Data: "Doe" }, 25],
[{ IndexValue: "R", Data: "Rammy" }, { IndexValue: "R", Data: "Ringer" }, 60],
[{ IndexValue: "Red", Data: "Raymond" }, { IndexValue: "R", Data: "Reddinton" }, 50],
]
for (const row of rows) {
await icd.upsert(row); // Upsert the rows into the data store
}
const mapper = async (rowIds) => {
const results = [];
for (const rowId of rowIds) {
results.push(await icd.get(rowId));
}
return results;
}
const results = await icd.getByIndexedColumn(0, "Johnny", mapper);// Get all rows with IndexValue of "Johnny"
console.log(results); // Output: [ [ { IndexValue: 'Johnny', Data: 'John' }, { IndexValue: 'D', Data: 'Doe' }, 30 ] ]
- Authors ❤️ for Open Source.
- New ideas/techniques are welcomed.
- Raise a Pull Request.
This project is contribution to public domain and completely free for use, view LICENSE.md file for details.