SectDB (SectDB.js)

October 05 2022. SectDB Documentation


SectDB is an free to use JavaScript library that provides powerful in-memory database capabilities to both browser and server applications such as Node.js

See SectDB Documentation: Here!

Introduction

Have you ever noticed how JavaScript object literals look a lot like records? And that if you wrap a group of them up in an array you have something that looks a lot like a database table? We did too. We created SectDB easily and efficiently manipulate these 'tables'
with a uniform and familiar SQL-like interface.

What makes it great

  • Extremely fast, small file size, extremely fast queries
  • Powerful JavaScript-centric data selection engine
  • SQL inspired features such as insert, update, unique, count, and more
  • Robust cross browser support
  • Easily extended with your own functions
  • Compatible with any DOM library (jQuery, YUI, Dojo, etc)
  • Compatible with Server Side JS

SectDB is compatible with all modern browsers: IE9+, FF3+, Safari 5+, and Chrome 1.0+. It also works in NodeJS 0.10+.

Download/Get SectDB

NPM: (NPM Package)

npm i sectdb

Paste it in your HTML file:

<script src="https://www.sectly.online/sectdb/sectdb.min.js"></script>

JavaScript File: Source (Great For Development)

Minified JavaScript File: Minified Source (Great For Browsers And Production)

Full Documentation:

See SectDB Documentation: Here!

Basics:

Create a DB (Database)

Just pass in a JSON array:

var products = SectDB([
  { "item"  : 1,
    "name"  : "Blue Ray Player",
    "price" : 99.99
  },
  { "item"  : 2,
    "name"  : "3D TV",
    "price" : 1799.99
  }
]);

Example queries

// where item is equal to 1
var item1 = products({item:1});

// where price is less than 100
var lowPricedItems = products({price:{lt:100}});

// where name is like "Blue Ray"
var blueRayPlayers = products({name:{like:"Blue Ray"}});

// get first record
products().first();

// get last record
products().last();

Example record manipulation

// update the price of the Blue Ray Player to 89.99
products({item:1}).update({price:89.99});

// loop over the records and call a function
products().each(function (r) {alert(r.name)});

// sort the records by price descending
products.sort("price desc");

// select only the item names into an array
products().select("name"); // returns ["3D TV","Blue Ray Player"]

// Inject values from a record into a string template.
// Row value will be set to "<tr><td>3D TV</td><td>17999.99</td></tr>"
var row = products({item:2})
  .supplant("<tr><td>{name}</td><td>{price}</td></tr>");

Use it in Node.JS

SectDB is easy to use in Node.JS. Simply copy the source code from the download page make a new JavaScript file name it SectDB.js paste the source code in and require the file:

const SectDB = require( 'SectDB' ).SectDB;

Home Page
Scroll Down For Page Copyright Info.