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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@xwink/dao

v0.0.4

Published

![版本](https://img.shields.io/badge/version-0.0.1-blue.svg?cacheSeconds=2592000) [![文档](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://github.com/x-wink/wink-dao#readme)

Downloads

65

Readme

😉 欢迎使用 @xwink/dao

版本 文档

💎 安装依赖

npm install --save @xwink/dao
pnpm add --save @xwink/dao

📖 快速入门

创建实例

import { useDao, QueryBuilder } from '@xwink/dao';

const dao = useDao({
    config: {
        host: '',
        port: 0,
        user: '',
        password: '',
        datebase: '',
    },
    debug: true,
    removeOptions: {
        controlField: 'del_flag',
        normalValue: 0,
        removedValue: 1,
    },
});

创建数据表

interface TestEntity {
    id: number;
    name: string;
    phone: string;
    age: number;
    sex: number;
    delFlag: boolean;
    createTime: Date;
    updateTime: Date;
    removeTime: Date;
}
const table = 't_user';
await dao.exec(`
    create table if not exists ${table} (
        id int primary key auto_increment,
        name varchar(255) not null,
        phone varchar(20) not null,
        age int not null default 0,
        sex int not null default 0,
        del_flag tinyint not null default 0,
        create_time datetime not null default now(),
        update_time datetime,
        remove_time datetime,
        unique (phone)
    )
`);

删除数据表

await dao.exec(`drop table if exists ${table}`);

插入数据

const data: Partial<TestEntity> = {
    name: 'test',
    phone: '10086',
};
// 单条数据
const id = await dao.insert({ table, data: [data] });
// 批量插入
await dao.insert({
    table,
    data: Array.from({ length: total - 1 }, (_, index) => ({
        name: Math.random().toString(36).substring(2, 8),
        phone: 1.32e10 + index,
        age: index,
        sex: index % 2,
    })),
});

统计数量

const count = await dao.count({ table, where: { sex: 0 } });

主键查询

const entity = await dao.detail<TestEntity>(table, id);

查询单条

const entity = await dao.get<TestEntity>({ table, where: { id } });

条件查询

const entities = await dao.select<TestEntity>({ table, where: { sex: 0 } });

分页查询

const page = await dao.page<TestEntity>({ table, where: { sex: 0 }, page: [1, 10] });
console.info(page.list);
console.info(page.total);

高级查询

const condition = { name: 'test' };
const builder = new QueryBuilder()
    .from(table)
    .equal('sex', 0, () => typeof condition.sex !== 'undefined')
    .like('name', condition.name, () => typeof condition.name !== 'undefined')
    .orderBy('age', 'desc')
    .page(1, 10);
const entities = await dao.query<TestEntity>(builder);

更新数据

const count = await dao.update({ table, data: { name: 'new test' }, where: { id } });

逻辑删除

const count = await dao.remove({ table, where: { id } });

逻辑恢复

const count = await dao.revoke({ table, where: { id } });

物理删除

const count = await dao.deletion({ table, where: { id } });

📦 进阶使用

import { useOrm, AutoTablePolicies, ColumnType } from '@xwink/dao';
const orm = useOrm(dao, { autoTablePolicy: AutoTablePolicies.UPDATE, normalrizeName: true });

创建仓库

const repository = registRepository<TestEntity>({
    name: table,
    columnDefines: [
        {
            name: 'id',
            type: ColumnType.INT,
            autoIncrement: true,
            primary: true,
            required: true,
            comment: '自增主键',
        },
        {
            name: 'delFlag',
            type: ColumnType.BOOLEAN,
            required: true,
            defaultValue: '0',
            comment: '逻辑删除标识',
        },
        {
            name: 'createTime',
            type: ColumnType.DATETIME,
            required: true,
            defaultValue: 'CURRENT_TIMESTAMP',
            comment: '创建时间',
        },
        {
            name: 'updateTime',
            type: ColumnType.DATETIME,
            comment: '修改时间',
        },
        {
            name: 'removeTime',
            type: ColumnType.DATETIME,
            comment: '移除时间',
        },
        {
            name: 'name',
            type: ColumnType.STRING,
            length: 64,
            required: true,
        },
        {
            name: 'phone',
            type: ColumnType.STRING,
            length: 20,
            required: true,
            unique: true,
        },
        {
            name: 'sex',
            type: ColumnType.INT,
            defaultValue: '0',
            required: true,
        },
        {
            name: 'age',
            type: ColumnType.INT,
            defaultValue: '0',
            required: true,
        },
    ],
});

主键查询

const entity = await repository.detail(id);

单条查询

const entity = await repository.get({ where: { id } });

条件查询

const entities = await repository.select({ where: { sex: 0 } });

数量查询

const count = await repository.count({ where: { sex: 0 } });

分页查询

const page = await repository.page({ where: { sex: 0 }, page: [1, 10] });
console.info(page.list);
console.info(page.total);

高级查询

const condition = { name: 'test' };
const builder = new QueryBuilder()
    .from(table)
    .equal('sex', 0, () => typeof condition.sex !== 'undefined')
    .like('name', condition.name, () => typeof condition.name !== 'undefined')
    .orderBy('age', 'desc')
    .page(1, 10);
const entities = await repository.query<TestEntity>(builder);

插入数据

const id = await repository.create([data]);

更新数据

const successful = await repository.update(data, { where: { id } });

逻辑删除

const successful = await repository.remove([id]);

逻辑恢复

const successful = await repository.revoke([id]);

物理删除

const successful = await repository.deletion([id]);

执行自定义语句

const entities = await repository.exec<TestEntity[]>(`select * from ${table} where sex = ? sort by age desc`, [0]);

📄 待办列表

  • [ ] 【feat-relaction】处理关联关系
  • [ ] 【refactor-adapter】支持适配多种数据库
  • [ ] 【feat-docs】新增vitepress文档项目并完善文档
  • [ ] 【chore】寻找伙(da)伴(lao)一起合作

🆘问题求助

🎯 框架依赖

👤 作者

向文可

  • Email: 1041367524@qq.com
  • Github: @x-wink

🤝 贡献

欢迎大家随时点击这里为我提供贡献、问题和功能建议

😘 感谢支持

如果觉得项目对你有帮助,就帮我点个小星星吧~ ⭐️