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 🙏

© 2026 – Pkg Stats / Ryan Hefner

smart-crud-client

v0.1.5

Published

一个轻量级的前端数据库 CRUD 操作解决方案,无需编写后端代码即可连接数据库

Readme

Smart CRUD Client

一个轻量级的前端数据库 CRUD 操作解决方案,无需编写后端代码即可连接数据库。

功能特性

  • 💻 前端框架支持:可用于 Vue 和 React 项目
  • ⚙️ 数据库兼容:支持 MySQL、SQLite、PostgreSQL
  • 📁 多表自动路由:自动生成多表的 CRUD 接口(RESTful)
  • 🔧 前端配置连接信息:前端提供配置(数据库类型、连接信息、表名)
  • 📦 构建后可部署:打包后仍然可以访问数据库,无需单独启动后端
  • 🚀 开箱即用:引入包 + 写配置 + 调用接口 = 拿到数据库数据

安装

npm install smart-crud-client

smart-crud-client/ ├── plugin/ # 构建 & dev 插件 │ └── vitePlugin.js # 注册插件:dev 启动服务 + 自动注入接口 ├── runtime/ │ ├── server.js # 启动 express 服务并连接数据库 │ ├── routerFactory.js # 动态创建 CRUD 接口 │ ├── db.js # 使用 knex 封装连接逻辑 ├── client/ │ └── useCRUD.js # 提供 hooks/工具函数给前端调用 ├── smart-crud.config.schema.json # 校验配置结构 ├── index.js # 导出 vite 插件 & client 工具

使用方法

配置文件 (smart-crud.config.js)

module.exports = {
	dbType: 'mysql', // 'mysql', 'sqlite', 'pg'
	connection: {
		host: 'localhost',
		user: 'root',
		password: 'password',
		database: 'mydb',
	},
	tables: ['users', 'products', 'orders'], // 需要生成CRUD接口的表
}

在 Vite 项目中使用

// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' // 或 react
import { smartCRUDPlugin } from 'smart-crud-client'
import crudConfig from './smart-crud.config.js'

export default defineConfig({
	plugins: [vue(), smartCRUDPlugin(crudConfig)],
})

在前端组件中使用

// Vue 组件
import { useCRUD } from 'smart-crud-client'

export default {
	setup() {
		const { users } = useCRUD()

		// 获取所有用户
		const fetchUsers = async () => {
			const data = await users.getAll()
			console.log(data)
		}

		// 创建用户
		const createUser = async () => {
			await users.create({ name: 'John', email: '[email protected]' })
		}

		return { fetchUsers, createUser }
	},
}

数据库配置示例

MySQL

{
  dbType: 'mysql',
  connection: {
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'password',
    database: 'mydb'
  },
  tables: ['users', 'products']
}

PostgreSQL

{
  dbType: 'pg',
  connection: {
    host: 'localhost',
    port: 5432,
    user: 'postgres',
    password: 'password',
    database: 'mydb'
  },
  tables: ['users', 'products']
}

SQLite

{
  dbType: 'sqlite',
  connection: {
    filename: './mydb.sqlite'
  },
  tables: ['users', 'products']
}

API 参考

useCRUD()

返回一个对象,包含每个表的 CRUD 操作方法。

每个表对象包含以下方法:

  • getAll(params) : 获取所有记录,支持过滤、排序和分页
  • getById(id) : 获取单个记录
  • create(data) : 创建新记录
  • update(id, data) : 更新记录
  • delete(id) : 删除记录

许可证

MIT