Giter VIP home page Giter VIP logo

jsql's Introduction

ManyDexJS

This is a light-weight package that allows for in-memory querying of semi-stuctured data, as well as write & reading the data to file. The package's big advantage is the heavily partitioned data structure, which provides the following benefits:

  1. When querying based on primary keys, results return in O(1)
  2. When querying based on partition keys, results return in ~O(n/p), n being total data size, p being number of partitions
  3. When querying based on other keys, including partition keys in your query will greatly improve performance

Create a database (new or existing)

let db = new database({ dbname: "test_db", folder_path });

**Read from file. **If you already have data in file with the same db_name and folder_path specified above, you can read the DB file file -> memory

await db.read_from_file();

Add a new table. Choose indices based on frequently-used query patterns, as including them in queries will greatly improve performance

db.add_table({ table_name: "person_test", indices: ["birth_year", "birth_state"], primary_key: "person_id" });

Insert data. Data can either be single element or array of elements. Elements must have field with PK defined

db.tables.person_test.insert(data);

Query data.

let results_1994_CA = db.tables.person.find({birth_year: 1994, birth_state: "CA"});
let results_1994 = db.tables.person.find({birth_year: 1994});
let results_pid_1 = db.tables.person.findOne({person_id: 1});
let results_pid_1_eq = db.tables.person.findOne({ person_id: { $eq: 1 } });
let results_matts = db.tables.person.find({name: "Matt"});
let results_1990_1994 = db.tables.person.find({$or: [{birth_year: 1990}, {birth_year: 1994}]});
let results_gt_1992 = db.tables.person.find({birth_year: {$gt: 1992}});

Save database & write to file

await db.save_database();

Query operators, largely using industry-standard

Operator Notes
$eq Value equals
$ne Value not equal
$gt Value greater than
$gte Value greater than or equal to
$lt Value less than
$lte Value less than or equal to
$in Value in an array
$nin Value not in an array
$or Logical OR of multiple queries

Development & use

When in the folder, run the below command to install all packages needed (really only fs & path)

npm install

To run the test script, simply run the below command

npx ts-node src/test.ts

jsql's People

Contributors

tomkennedy22 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.