📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

wink-dao

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

wink-dao

欢迎使用WinkDao 👋 <img alt="Documentation" src="https:

2.0.5-beta.0
unpublished
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

欢迎使用WinkDao 👋

Version Documentation

📚 各版本文档

  • v1.x

  • v2.x

👇 安装依赖

npm install --save wink-dao
pnpm add --save wink-dao

📖 示例代码

import { useDao, useOrm, AutoTablePolicies, ColumnType, AutoIncrementEntity, ExecResult } from 'wink-dao';

// DAO基础操作库
const dao = useDao({
    config: {
        host: '',
        port: 0,
        user: '',
        password: '',
        datebase: '',
    },
});
const { exec, get, select, insert, update, remove, revoke } = dao;
// 使用ORM框架
const { registRepository } = useOrm(dao, {
    // 开启自动托管数据表后会自动创建表,表名会自动增加前缀t_,并将表名和字段名的驼峰命名转为下划线
    // TODO 自动同步更新表结构暂未实现
    autoTablePolicy: AutoTablePolicies.CREATE,
});
// 定义Menu模型,推荐使用自增主键
class Menu extends AutoIncrementEntity {
    name?: string;
    code?: string;
    sort?: number;
    isDirectory?: boolean;
    constructor(data?: Partial<Menu>) {
        super();
        Object.assign(this, data);
    }
}
// 配置Menu仓库
const repository = registRepository({
    name: 'menu',
    columnDefiens: [
        {
            name: 'name',
            type: ColumnType.STRING,
            length: 20,
            required: true,
        },
        {
            name: 'code',
            type: ColumnType.STRING,
            length: 20,
            required: true,
            primary: true,
            unique: true,
        },
        {
            name: 'sort',
            type: ColumnType.INT,
            required: true,
            defaultValue: '0',
        },
        {
            name: 'isDirectory',
            type: ColumnType.BOOLEAN,
            required: true,
            defaultValue: 'false',
        },
    ],
});
// 实际应该在项目启动时初始化
await repository.init.run();
// 插入数据
const id = await repository.create(new Menu({ code: 'test', name: '测试' }));
// 主键查询
const menu = await repository.get<Menu>(id);
// 更新数据
menu.sort = 10;
let isSuccess: boolean = await repository.update(menu);
// 条件查询
const list: Menu[] = await repository.select<Menu>({ code: 'test' });
// 逻辑删除
isSuccess = await repository.remove(id);
// 逻辑恢复
isSuccess = await repository.revoke(id);
// 自定义查询
const menus: Menu[] = await repository.exec<Menu[]>('select * from t_menu where sort > ?', [0]);
// 自定义操作
const result: ExecResult = await repository.exec('delete from menu where id = ?', [id]);
// result.affectedRows === 1

😉 TODO

  • 【feat-orm】新增ORM框架
  • 【feat-relaction】处理关联关系(很复杂)
  • 【refactor-plugin】抽离Mysql耦合,改为插件形式
  • 【refactor-adapter】支持适配多种数据库
  • 【perf-dao】优化DAO基础能力
  • 【feat-business】封装分页查询等常用业务能力
  • 【feat-generate】参考JPA实现通过函数名特殊命名规则生成复杂查询
  • 【feat-docs】新增vitepress文档项目并完善文档
  • 【refactor-test】改用vitest测试用例完善开发发布流程
  • 【feat-update】实现同步更新表结构(尝试了一下比想象中复杂)
  • 【chore】寻找伙(da)伴(lao)一起合作

🎯 框架依赖

  • mysql MySQL 数据库协议

👤 作者

向文可

🤝 贡献

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

😘 感谢支持

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

本文档使用readme-md-generator模板生成

Keywords

dao

FAQs

Package last updated on 17 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts