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

laf-db-query-wrapper

v1.0.26

Published

laf-client-sdk 查询语法包装

Downloads

15

Readme

简介

laf-client-sdk / database-ql 数据库操作语法包装, 借鉴 MyBatis-Plus 的链式查询语法, 优化单表 CRUD 操作, 避免频繁的判断响应状态, 构建 where 参数; 同时提供完整 model 类型提示;

开始

安装

npm install laf-db-query-wrapper -S

配置

在项目目录下任意位置:

import {LafWrapperConfig} from 'laf-db-query-wrapper'
// 你的 laf-client-sdk cloud 对象
import {cloud} from '@/config/LafClientSdkConfig'

// 最小配置
LafWrapperConfig.cloud = () => cloud
// 自定义日志实现
LafWrapperConfig.LoggerFactory = myLoggerFactory
// 设置日志等级, LoggerLevel.ALL 是默认值
LafWrapperConfig.LoggerFactory.enableLevel = LoggerLevel.ALL

使用

单表, 单记录(文档) 增删改查操作: LafClient

import {LafClient} from 'laf-db-query-wrapper'

export class AccountService {
    private readonly client = new LafClient<Account>(Account.TABLE_NAME)

    private async test() {
        // 新增
        const id: string | number = await this.client.insert({})
        // 查
        const account: Account | null = await this.client.selectById('<ID>')
        // 更新
        const updateOk: boolean = await this.client.updateById('<ID>', {}, '_id')
        // 删除
        const deleteOk: boolean = await this.client.deleteById('<ID>')

    }
}

分页查询, 列表查询, 计数, 等复杂查询: QueryChainWrapperUpdateChainWrapper

详细的操作见类型提示和方法文档注释

import {QueryChainWrapper} from 'laf-db-query-wrapper'
import {UpdateChainWrapper} from 'laf-db-query-wrapper'

// 直接 new 然后使用链式操作
new QueryChainWrapper('<TableName>')
new UpdateChainWrapper('<TableName>')

// 或者使用上例中的 `LafClient` 本质上就是在方法内 new 对象, 只是复用了 LafClient 的 tableName
this.client.queryWrapper()
this.client.updateWrapper()
/* 数据库表模型定义  */
class Account {
    public static readonly TABLE_NAME: string = 'sys_account'
    id: number
    name: string
    password: string
    level: number
    avatarId: number
}
class Resource {
    public static readonly TABLE_NAME = 'sys_resource'
    id: number
    path: string
    type: 1 | 2 | 3
    createTime: number
}

// 分页查询
new QueryChainWrapper<Account>(Account.TABLE_NAME)
    .eq('name', '')
    .neq('level', 123)
    .page(new Page<Account>(1, 20))
    .then((page: Page<Account>) => {
        page.list.forEach(i => {

        })
    })

// 关联查询
const withResource = new QueryChainWrapper<Resource>(Resource.TABLE_NAME)
    .eq('type', 1)
    .show('path')
    .orderByDesc('createTime')
    .getWithArg<Account>('id', 'avatarId', 'avatar')

new QueryChainWrapper<Account>(Account.TABLE_NAME)
    .withOne(withResource)
    .list(1000)
    .then(list => {
        console.debug(list)
    })

仓库地址

https://gitee.com/song-yan-ru-mo_admin/laf-db-query-wrapper