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

@edit-all/kore-db

v0.1.2

Published

IndexedDB wrapper like RDB (CRUD, left inner join, where, order)

Downloads

172

Readme

koreDB

IndexedDB wrapper like RDB (CRUD, left inner join, where, order)

run sample

pnpm sample dev
pnpm todo dev

Usage

all code is in apps/vite-project/src/main.ts

1. Define schema

Defining a static schema by inheriting from the Table class.

class Member extends Table<Member>{
    $rowid!:number;
    name!:string;
}

class Club extends Table<Club>{
    $rowid!:number;
    name!:string;
}

class MemberClub extends Table<MemberClub>{
    $rowid!:number;
    member_rowid!:number;
    club_rowid!:number;
}

2. Make Database instance

class TestDB extends DB{
    constructor(dbName:string){
        super(dbName);
    }
    onCreate(table:CreateTable):void{
        table(Member).index("name");
        table(Club).index("name");
        table(MemberClub).index("member_rowid").index("club_rowid");
    }
    async onInit():Promise<void>{
        console.log("onInit");
        await this.insert(Member,
            new Member().from({name:"hika"}),
            new Member().from({name:"jidolstar"}),
            new Member().from({name:"boeun"})
        );
        await this.insert(Club,
            new Club().from({name:"baseball"}),
            new Club().from({name:"football"}),
            new Club().from({name:"swimming"})
        );
        await this.insert(MemberClub,
            new MemberClub().from({club_rowid:1, member_rowid:1}),
            new MemberClub().from({club_rowid:1, member_rowid:2}),
            new MemberClub().from({club_rowid:2, member_rowid:2}),
            new MemberClub().from({club_rowid:2, member_rowid:3}),
            new MemberClub().from({club_rowid:3, member_rowid:1}),
            new MemberClub().from({club_rowid:3, member_rowid:3})
        );
    }
    onError(e:Event):void{
        console.error(e);
    }
}

const testDB = new TestDB("test");

3. Make query

select member.rowid as memberId, member.name as memberName, club.rowid as clubId, club.name as clubName
select member.*, memberClub.*, club.*
from Member member
left inner join MemberClub memberClub on member.rowid = memberClub.member_rowid
left inner join Club club on memberClub.club_rowid = club.rowid
where member.name = "hika" or club.name = "baseball"
order by memberId, clubId

to Kore DB query

const query1 = await testDB.select(Member, (query, member)=>{
    const memberClub = member.join(MemberClub, "member_rowid", "$rowid")
    const club = memberClub.join(Club, "$rowid", "club_rowid")
    query.project(member, "$rowid", "memberId")
        .project(member, "name", "memberName")
        .project(club, "$rowid", "clubId")
        .project(club, "name", "clubName")
        .E(member, "name", 0, "memberName")
        .OR.E(club, "name", 0, "clubName")
        .orderBy("memberId")
        .orderBy("clubId")
});

4. run query

const v = await query1.query({memberName:"hika", clubName:"baseball"});
console.log(v);

and result is

[
  {"memberId":1,"memberName":"hika","clubId":1,"clubName":"baseball"},
  {"memberId":1,"memberName":"hika","clubId":1,"clubName":"baseball"},
  {"memberId":1,"memberName":"hika","clubId":3,"clubName":"swimming"},
  {"memberId":2,"memberName":"jidolstar","clubId":1,"clubName":"baseball"}
]