npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lsflexdb

v1.0.4

Published

A lightweight local storage database library for browser and Angular.

Downloads

280

Readme

lsflexdb

lsflexdb is a lightweight library for managing data in localStorage, allowing you to create tables and perform basic CRUD operations with ease.

Features

  • Create tables in localStorage
  • Automatic or manual data saving
  • Support for basic CRUD operations (Create, Read, Update, Delete)
  • Data filtering and ordering capabilities
  • Designed for use in both browsers and Angular projects

Installation

Install the package using the following command:

npm install lsflexdb

Usage

First, import the library.

Angular


import lsflexDB from 'lsflexdb';

Browser

Include the script in your HTML file:


<script src="path/to/lsflexdb.js"></script>

Create Database

Create an instance of the database:

// Create a new database instance
const lsDB_blog = new lsflexDB("blog", { auto_save: true });

Methods

1. create(tableName, structure)

Creates a new table with the specified structure.

  • tableName: The name of the table
  • structure: An object defining the table's columns
lsDB_blog.create("users", {
    username: "",
    password: "",
    is_active: 0
});

2. select(where)

Retrieves data from the table with optional filtering.

  • where (optional): An object specifying filter conditions
// Get all users
let allUsers = lsDB_blog.users.select();

// Filter users based on conditions
let activeUsers = lsDB_blog.users.select({ is_active: 1 });

3. insert(values, options)

Adds new data to the table.

  • values: An object containing the new data
  • options (optional): Settings for saving, { save: true | false }
lsDB_blog.users.insert({
    username: "admin",
    password: "12345",
    is_active: 1
}, { save: true });

4. update(data, where, options)

Updates existing data in the table.

  • data: An object containing the new values
  • where: Filter conditions for selecting rows to update
  • options (optional): Settings for saving, { save: true | false }
lsDB_blog.users.update(
    { is_active: 0 },
    { username: "admin" },
    { save: true }
);

5. delete(where, options)

Removes data from the table.

  • where: Filter conditions for selecting rows to delete
  • options (optional): Settings for saving, { save: true | false }
lsDB_blog.users.delete({ username: "admin" }, { save: false });

6. save()

Manually saves the data to localStorage.

lsDB_blog.users.save();

Using Different where Conditions

The where parameter supports various conditions for filtering data:

  1. Basic Equality

    // Select users with a specific email
    let userByEmail = lsDB_blog.users.select({ email: "[email protected]" });
  2. Comparison Operators

    • > (greater than), >= (greater than or equal), < (less than), <= (less than or equal)
    // Select users with user_id greater than 200
    let usersAbove200 = lsDB_blog.users.select({ "user_id[>]": 200 });
    
    // Select users with user_id less than or equal to 300
    let usersBelow300 = lsDB_blog.users.select({ "user_id[<=]": 300 });
  3. Not Equal

    // Select users who are not active
    let inactiveUsers = lsDB_blog.users.select({ "is_active[!]": 1 });
  4. Pattern Matching

    • LIKE operator using [~]
    // Select users where city contains 'lon'
    let usersInLondon = lsDB_blog.users.select({ "city[~]": "lon" });
  5. Between

    // Select users with age between 20 and 30
    let usersIn20s = lsDB_blog.users.select({ "age[<>]": [20, 30] });
    
    // Select users with age not between 40 and 50
    let usersOutside40s = lsDB_blog.users.select({ "age[><]": [40, 50] });
  6. In Array

    // Select users with specific user_ids
    let specificUsers = lsDB_blog.users.select({ user_id: [2, 123, 234, 54] });
    
    // Select users with specific emails
    let specificEmails = lsDB_blog.users.select({ email: ["[email protected]", "[email protected]", "[email protected]"] });
  7. Custom Filtering Function

    // Use a custom function to filter users
    let customFilteredUsers = lsDB_blog.users.select({
        age: (value) => value > 20 && value < 50
    });

Complete Example

import { lsflexDB } from 'lsflexdb';

// Create the database
const lsDB_blog = new lsflexDB("blog", { auto_save: true });

// Create the 'users' table
lsDB_blog.create("users", {
    username: "",
    password: "",
    is_active: 0
});

// Insert a new user
lsDB_blog.users.insert({
    username: "admin",
    password: "12345",
    is_active: 1
});

// Update the user's status
lsDB_blog.users.update(
    { is_active: 0 },
    { username: "admin" }
);

// Get active users
let activeUsers = lsDB_blog.users.select({ is_active: 1 });

// Delete the user
lsDB_blog.users.delete({ username: "admin" });