lightweight-data-table

4.1.0 • Public • Published

Data Table

This module is designed to provide a lightweight searchable data collection in browser with easy import and export functionalizty. Inspired by c#'s lists and linq. Origionaly built to provide data management in an electron app.

Example Usage

"use strict";

const table = require('./index.js').table; //lightweight-data-table

/*
Define your schema
 */
const schema = {};

schema.person = {
	name: 'New Person',
	age: 0,
	export: function() {
		return {
			typeName: 'person',
			content: {
				name: this.name,
			    age: this.age
			}
		};
	},
	import: function(data, schema) {
		this.name = data.name;
		this.age = data.age;
	}
};

schema.group = {
	name: "New Place",
	members: new table(),
	export: function(data, schema) {
		return {
			typeName: 'group',
			content: {
				name: this.name,
				members: this.members.export()
			}
		};
	},
	import: function(data, schema) {
		this.name = data.name;
		this.members.import(data.members, schema);
	}
};


const people = new table();
const groups = new table();

/*
Add entries to table
 */

const me = Object.create(schema.person);
me.name = "Joe";
people.add(me);

const group = Object.create(schema.group);
group.name = 'JS Developers';
group.members.add(me);

groups.add(group);


/*
Get values from table
 */

let person = people.get(1); //This will get the person entry with an Id of 1. In this case it will be our me var.

/*
Export data
 */
let data = groups.export();

/*

Exported Data:

[{
	typeName: 'group',
	content: {
		name: 'JS Developers',
		members: [{
			typeName: 'person',
			content: {
				name: 'Joe',
				age: 0
			}
		}]
	}
}]
*/

/*
Import data
 */
let newGroupTable = new table();
newGroupTable.import(data, schema);

/*
Search Data (support multiple search arguments)
 */
groups.select([{
	//Can also be path to field, e.g. 'Field.ParentObjectField.ParentObjectField.etc'. Path can include functions with no arguments.
	field: 'name', 

	// Supports 'greater', 'equal', 'less than', and regular expressions. For regex the value field is ignored.
	match: 'equal', 
	//Value to search for. Supports numbers, dates, and strings.
	value: 'JS Developers' 
}]);

Readme

Keywords

none

Package Sidebar

Install

npm i lightweight-data-table

Weekly Downloads

1

Version

4.1.0

License

ISC

Last publish

Collaborators

  • brain-bit-studios