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

lite-ts-db

v11.24.8

Published

```typescript const dbFactory: DbFactoryBase;

Downloads

69

Readme

Version

代码

DbFactoryBase - 数据库工厂

const dbFactory: DbFactoryBase;

// 创建数据仓储
class MyModel extends DbModel {}
const res = dbFactory.db<MyModel>(
    modelDbOption(MyModel),
);

// 创建工作单元
const res = dbFactory.uow();
  • ProjectDbFactory - 项目数据库
const globalDbFactory: DbFactoryBase;
const getAllProjectDbFactoryFunc: () => Promise<{
    [projectNo: number]: {
        [areaNo: number]: DbFactoryBase;
    };
}>;
const dbFactory: DbFactoryBase = new ProjectDbFactory(
    globalDbFactory,
    getAllProjectDbFactoryFunc,
);

// 创建区服数据库
const areaDbFactory = await dbFactory.buildAreaFactory(区服编号, 项目编号);

IDbQuery - 数据查询

const dbFactory: DbFactoryBase;
const dbQuery = dbFactory.db(
    modelDbOption(表模型),
).query();

// 查询数量
const count = await db.query().count(查询条件);

// 查询行
const rows = await db.query().toArray({
    skip: 跳过[可选],
    take: 获取多少行[可选],
    where: 查询条件[可选],
    // 可选
    order: [正序字段1, ..., 正序字段n],
    // 可选
    orderByDesc: [倒序字段1, ..., 倒序字段n]
});
  • ProjectDbQuery<T extends DbModel> - 项目数据查询
class MyModel extends DbModel {}
const dbRepository: DbRepository<MyModel>;
const projectDbFactory: ProjectDbFactory;
const dbQuery: = new ProjectDbQuery<MyModel>(dbRepository, projectDbFactory);

IDbRepository<T extends DbModel> - 数据仓储

const dbFactory: DbFactoryBase;
const dbRepo = dbFactory.db(
    modelDbOption(表模型),
);

// 新增
await db.add(表模型实体);

// 更新
await db.save(表模型实体);

// 删除
await db.remove(表模型实体);
  • DbRepository<T extends DbModel> - 数据仓储
class MyModel extends DbModel {}
const dbRepo: IDbRepository<MyModel> = new DbRepository<MyModel>();

UnitOfWorkBase - 工作单元(事务)

const dbFactory: DbFactoryBase;
const uow = dbFactory.uow();
const dbRepo = dbFactory.db(
    modelDbOption(表模型),
    uowDbOption(uow),
);

await db.add(表模型实体);
await db.save(表模型实体);
await db.remove(表模型实体);

// 提交后数据才会更新到数据库
await uow.commit();

UnitOfWorkRepositoryBase - 工作单元仓储(基类)

const uow: UnitOfWorkRepositoryBase;

// 注册新增
uow.registerAdd(模型名, 实体);

// 注册删除
uow.registerRemove(模型名, 实体);

// 注册保存
uow.registerSave(模型名, 实体);
  • ProjectUnitOfWork - 项目工作单元
const projectDbFactory: ProjectDbFactory;
const uow: UnitOfWorkBase = new ProjectUnitOfWork(projectDbFactory);