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

sqlike

v0.0.78

Published

Simplification of SQLite with strong typing of table fields (taking advantage on TypeScript typing)

Downloads

8

Readme

This package simplifies SQLite usage and ties your TS classes and tables together, so you don't have to create tables or care if your Table Class fields and their types match the corresponding SQLite table - the SQLike will do it for you automatically! And still, you have access to the raw SQL queries when you need these.

Installation

npm i sqlike -S

Usage


/**
 * this is a "typed table" object. The class name is used as a table name
 * and its fields - as columns.
 */
class User extends STable {
    /** @idx decorator defines that the index will be created for this 
     * field in SQLite */
    @idx user = ``;/** must init with an empty string, to let the SQLike
     know this is of a TEXT type */
    age = 0;/** must init with an number, to let the SQLike know this 
    is of a REAL type */
    blueEyes = false;
    email = ``;
    @uniq passportNumber = ``;/** using "@uniq" to let the system know 
    this is a UNIQUE fields in SQLite */
    notUsed!: string;/** if you don't init the property - it will 
    NOT become a field in the table */
    greetings=()=>`Hello, I am ${this.user}, ${this.age} y.o, 
                    my ID is ${this.passportNumber}`
}

    /// opening database. Will create if none:
    const like = await SQLike.open(`./testDb.sqlite`);

    /// opening table "User". Will create new if no table exists.
    /// note: a class name "User" becomes a table name in SQLite database
    const users = await like.table<User>(User);

    /// let`s create and insert one user
    const user = new User();
    user.user = `John`;
    user.age = 22;
    user.blueEyes = true;
    user.passportNumber = `` + Math.random();
    await users.insertOne(user);

    /// now let`s select one
    const someone = await users.selectOne(`age=?`, 22);
    /// "users.select()" will create an instance of a "User" class,
    /// so all its defined methods are callable:
    /// prints "Hello, my name is John, 22 y.o., my ID is 0.3493947247"
    console.log(someone.greetings())

    /// let`s change and update:
    someone.email = `hi.${Math.random()}@example.com`;
    const randAge = Math.random() * 20 + 10;
    someone.age = randAge;
    await users.updateOne(someone);

    /// now let`s check if it did actually update:
    const somebody = await users.selectOne(`email = ?`, someone.email);

    /// prints "Hello, my name is John, 18.94728437 y.o., my ID is 0.3493947247"
    console.log(someone.greetings())

That simple. No "sequential", no need to track if your field names in strings match your fields - here you take advantage on static TypeScript typing.