# knex-rest-api **Repository Path**: goodffff/knex-rest-api ## Basic Information - **Project Name**: knex-rest-api - **Description**: knex-rest-api - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-28 - **Last Updated**: 2026-03-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Knex REST — 全栈数据库即服务 通过 REST 接口驱动 KnexJS,四层架构,从 SQL 到面向对象一站式解决。 ``` hotel/ Vue 3 酒店管理系统 → 使用 ORM 装饰器和 Repository sdk/src/orm/ ORM 层 → @Entity @Column BaseModel Repository sdk/src/ SDK 层 → 链式 QueryBuilder (像 Knex) server/ Koa REST 服务 → JSON → Knex.js → SQL → Database ``` ## 快速启动 ```bash # 1. 启动服务端 cd server && npm install && npm run dev # 2. 启动酒店前端 cd hotel && npm install && npm run dev # 打开 http://localhost:5173 ``` ## 三种使用方式 ```typescript // ── ORM (面向对象,推荐) ── @Entity('users') class User extends BaseModel { @PrimaryKey() id!: number @Column('string') name!: string @HasMany(() => Post) posts?: Post[] } const users = orm.getRepository(User) const admins = await users.find({ where: { role: 'admin', age: { $gte: 18 } } }) const avg = await users.avg('age') await new User().fill({ name: 'Alice' }).save() // ── SDK (链式调用) ── const result = await db('users').select('id','name').where('age','>',18).orderByDesc('score').limit(10) // ── REST API (任何语言) ── POST /api/v1/data/users/query { "where": [...], "orderBy": [...] } ```