完整的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方面進行考慮。恢復試圖取得更好的平衡。
歡迎捐款。參見貢獻。
恢復是麻省理工學院許可的。