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

indexdb-util

v0.0.0-beta.3

Published

indexdb operate util toy.

Downloads

3

Readme

indexdb-util (beta,就是个玩具!!!)

使用类似 TypeOrm 的 manager api 的方法操作 indexdb

只能 TypeScript 使用,TypeScript 需要开启装饰器(原生 js 我也不知道怎么用,哈哈哈哈 😂)

需要配合vitewebpack等使用。

// tsconfig.json
{
  "compilerOptions": {
    "experimentalDecorators": true
  }
}

Install

# npm
npm i indexdb-util
# pnpm
pnpm add indexdb-util

Usage

声明一个 ObjectStore。

// student表示一个objectStore
@Entity("student")
// 普通索引
@CreateIndex("idx_name", "name")
// 唯一索引
@CreateUniqueIndex("uni_stdent_number", "student_number")
// 联合索引
@CreateIndex("idx_name_student_number", ["name", "student_number"])
export class Student {
  // @PrimaryGeneratedColumn() 表示id是主键。
  @PrimaryGeneratedColumn()
  id!: number;

  @Column()
  name!: string;

  @Column()
  student_number!: number;

  @Column()
  age!: number;
}

初始化 indexdb

const indexdbUtil = new IndexDBUtil({
  // indexdb 名称
  name: "school",
  // indexdb 版本
  version: 1,
  // 声明的objectStore
  entityList: [Student],
  // 当版本更改时会触发,可以做一些数据迁移的操作。
  versionChange(transaction, currentVersion, goalVersion) {},
});

indexdbUtil.connect().then(() = {
    // ... 可以开始操作
})

可以参考测试文件test/*

Api

indexdbUtil.manager;

interface ManagerOptions<T> {
  // 类型推断
  where?: { [K in keyof T]?: T[K] | CompareItem | CompareItem[] };
  limit?: number;
  skip?: number;
  order?: Array<{ [K in keyof T]?: "DESC" | "ASC" }>;
}

interface Manager {
  findOne<T extends AbstractClass>(
    Entity: T,
    options?: ManagerOptions<InstanceType<T>>
  ): Promise<InstanceType<T> | null>;
  find<T extends AbstractClass>(
    Entity: T,
    options?: ManagerOptions<InstanceType<T>>
  ): Promise<Array<InstanceType<T>>>;
  insertOne<T extends AbstractClass>(
    Entity: T,
    value: Partial<InstanceType<T>>
  ): Promise<IDBValidKey>;
  insert<T extends AbstractClass>(
    Entity: T,
    value: Partial<InstanceType<T>>[]
  ): Promise<IDBValidKey>;
  updateOne<T extends AbstractClass>(
    Entity: T,
    value: Partial<InstanceType<T>>,
    options?: ManagerOptions<InstanceType<T>>
  ): Promise<any>;
  update<T extends AbstractClass>(
    Entity: T,
    value: Partial<InstanceType<T>>,
    options?: ManagerOptions<InstanceType<T>>
  ): Promise<any>;
  deleteOne<T extends AbstractClass>(
    Entity: T,
    options?: ManagerOptions<InstanceType<T>>
  ): Promise<any>;
  delete<T extends AbstractClass>(
    Entity: T,
    options?: ManagerOptions<InstanceType<T>>
  ): Promise<any>;
}