完整的CRUD,简化,具有SSOT toxtript实体
Rebult使用打字稿实体作为以下事实的单一来源:✅crud +实时API,✅前端类型安全API客户端和✅后端ORM。
Remult支持所有主要数据库,包括:PostgreSQL,MySQL,SQLITE,MONGODB,MSSQL和ORACLE。
Remult是前端和后端框架不可知论的,并配备了Express,Fastify,Next.js,Nuxt,Sveltekit,Sveltekit,Solidstart,Nest,Koa,Hapi和Hono的适配器。
想亲身经历回归吗?尝试我们的交互式在线教程。
Rebult促进了前端和后端代码的一致查询语法:
// Frontend - GET: /api/products?_limit=10&unitPrice.gt=5,_sort=name
// Backend - 'select name, unitPrice from products where unitPrice > 5 order by name limit 10'
await repo ( Product ) . find ( {
limit : 10 ,
orderBy : {
name : 'asc' ,
} ,
where : {
unitPrice : { $gt : 5 } ,
} ,
} )
// Frontend - PUT: '/api/products/product7' (body: { "unitPrice" : 7 })
// Backend - 'update products set unitPrice = 7 where id = product7'
await repo ( Product ) . update ( 'product7' , { unitPrice : 7 } ) // shared/product.ts
import { Entity , Fields } from 'remult'
@ Entity ( 'products' , {
allowApiCrud : true ,
} )
export class Product {
@ Fields . cuid ( )
id = ''
@ Fields . string ( )
name = ''
@ Fields . number ( )
unitPrice = 0
}不喜欢装饰器吗?我们为没有装饰的人提供全力支持
例子:
// backend/index.ts
import express from 'express'
import { remultExpress } from 'remult/remult-express' // adapters for: Fastify,Next.js, Nuxt, SvelteKit, SolidStart, Nest, more...
import { createPostgresDataProvider } from 'remult/postgres' // supported: PostgreSQL, MySQL, SQLite, MongoDB, MSSQL and Oracle
import { Product } from '../shared/product'
const app = express ( )
app . use (
remultExpress ( {
entities : [ Product ] ,
dataProvider : createPostgresDataProvider ( {
connectionString : 'postgres://user:password@host:5432/database"' ,
} ) ,
} ) ,
)
app . listen ( )重新添加了功能齐全的REST API和REALTIME LIVE QUERY端点的路由处理程序,可选包括开放API规格和GraphQL端点
const [ products , setProducts ] = useState < Product [ ] > ( [ ] )
useEffect ( ( ) => {
repo ( Product )
. find ( {
limit : 10 ,
orderBy : {
name : 'asc' ,
} ,
where : {
unitPrice : { $gt : 5 } ,
} ,
} )
. then ( setProducts )
} , [ ] ) useEffect ( ( ) => {
return repo ( Product )
. liveQuery ( {
limit : 10 ,
orderBy : {
name : 'asc' ,
} ,
where : {
unitPrice : { $gt : 5 } ,
} ,
} )
. subscribe ( ( info ) => {
setProducts ( info . applyChanges )
} )
} , [ ] ) import { Entity , Fields , Validators } from 'remult'
@ Entity ( 'products' , {
allowApiCrud : true ,
} )
export class Product {
@ Fields . cuid ( )
id = ''
@ Fields . string ( {
validate : Validators . required ,
} )
name = ''
@ Fields . number < Product > ( {
validate : ( product ) => product . unitPrice > 0 || 'must be greater than 0' ,
} )
unitPrice = 0
} try {
await repo ( Product ) . insert ( { name : '' , unitPrice : - 1 } )
} catch ( e : any ) {
console . error ( e )
/* Detailed error object ->
{
"modelState": {
"name": "Should not be empty",
"unitPrice": "must be greater than 0"
},
"message": "Name: Should not be empty"
}
*/
} // POST '/api/products' BODY: { "name":"", "unitPrice":-1 }
// Response: status 400, body:
{
"modelState" : {
"name" : "Should not be empty" ,
"unitPrice" : "must be greater than 0"
} ,
"message" : "Name: Should not be empty"
}@ Entity < Article > ( 'Articles' , {
allowApiRead : true ,
allowApiInsert : Allow . authenticated ,
allowApiUpdate : ( article ) => article . author == remult . user . id ,
apiPrefilter : ( ) => {
if ( remult . isAllowed ( 'admin' ) ) return { }
return {
author : remult . user . id ,
}
} ,
} )
export class Article {
@ Fields . string ( { allowApiUpdate : false } )
slug = ''
@ Fields . string ( { allowApiUpdate : false } )
authorId = remult . user ! . id
@ Fields . string ( )
content = ''
} await repo ( Categories ) . find ( {
orderBy : {
name : 'asc ' ,
} ,
include : {
products : {
where : {
unitPrice : { $gt : 5 } ,
} ,
} ,
} ,
} )
// Entity Definitions
export class Product {
//...
@ Relations . toOne ( Category )
category ?: Category
}
export class Category {
//...
@ Relations . toMany < Category , Product > ( ( ) => Product , `category` )
products ?: Product [ ]
}
虽然简单的CRUD不应需要任何后端编码,但使用Remult意味着通过以多种方式控制后端来处理任何复杂方案的能力:
Remult软件包对于前端捆绑包和后端都是相同的。将其安装一次用于Monorepo中的Monolith项目或每次repo。
npm i remult学习恢复的最佳方法是遵循使用Node.js Express Backend的简单TODO Web应用程序的教程。

在此处观看YouTube上的代码演示(14分钟)
该文档涵盖了Remult的主要特征。但是,这仍然是一个正在进行的工作。
fullStack to domvc示例与React和Express。 (源代码|代码框)
具有React + MUI前端和Postgres数据库的CRM演示。
Remult已准备就绪,实际上是自2018年以来用于生产应用程序中的。但是,我们将主要版本保持在零,因此我们可以使用社区反馈来最终确定V1 API。
全栈网络开发(仍然)太复杂了。任何业务应用程序的普遍要求,应易于构建,维护和扩展。
一方面,Remult Remult摘要重复,样板,容易出错和设计较差的代码,另一方面可以完全灵活性和控制。 Rebult帮助仅使用打字稿代码构建Fullstack应用程序,您可以轻松地跟随并安全地进行重构,并通过简约且完全不公开对开发人员选择其他框架和工具的选择,非常适合任何现有或新的项目。
其他框架往往会陷入过多的抽象(无代码,低代码,BAA)或部分抽象(MVC框架,GraphQl,Orms,Orms,API Generator,代码发生器),并且倾向于在开发工具链,部署环境,配置/会议或DSL方面进行考虑。恢复试图取得更好的平衡。
欢迎捐款。参见贡献。
恢复是麻省理工学院许可的。