1.0.0 • Published 3 years ago
@rugo-vn/model v1.0.0
Rugo Model
Rugo Drivers for contact with drivers.
Usage
Create Models
Independent
import { createModel } from 'rugo-model';
const model = createModel(driver, schema);Plugin
import ModelPlugin from 'rugo-model/plugin';
context = await ModelPlugin(context, {
drivers,
schemas
});Basic Operation
await model.get(id);
await model.list(query);
await model.create(doc);
await model.patch(id, doc);
await model.remove(id);Schema
{
"__name": "model-name", // aka collection name
"__type": "driver-type", // with fs type, it auto schema
}Common Triggers
required
Required field must be set when create. Default: false.
default
Default data if field is not set when create.
Default functions
Basic syntax:
%<functionName>:<params...>%params is separated by comma (,).
Defined functions:
%unislug:title%Unique slug
editable
Field can be patch or not. Default: true.
Types
Number
minmax
Text
minLengthmaxLengthregextrimlowercaseuppercaseenum
API
License
MIT