https://github.com/voltraco/dml
A data modeling language (for node and the browser)
https://github.com/voltraco/dml
data-model data-validation modeling
Last synced: 10 months ago
JSON representation
A data modeling language (for node and the browser)
- Host: GitHub
- URL: https://github.com/voltraco/dml
- Owner: voltraco
- License: mit
- Created: 2016-02-02T01:58:25.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-12-09T15:08:59.000Z (about 8 years ago)
- Last Synced: 2025-04-10T04:18:24.957Z (10 months ago)
- Topics: data-model, data-validation, modeling
- Language: JavaScript
- Homepage: http://dml.sh
- Size: 66.4 KB
- Stars: 62
- Watchers: 2
- Forks: 11
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SYNOPSIS
A data modeling language reference implementation. See [dml.sh](http://dml.sh)
# BUILD
[](https://travis-ci.org/voltraco/dml)
# USAGE
### sample.model
Define a model using the data modeling language syntax
```js
// An example data model
Date created
Number id
String name
require // this is a comment
gt 2 "Must be greater than 2 characters"
lte 256 "Must be less than or equal to 256 characters"
String bio "A bio must be a string"
lte 140 "A bio must fit into a tweet"
Boolean accountType
```
### index.js
Compiling a model returns a function that will validate data.
```js
const Models = require('node-dml')
let model = Models.compile(fs.readFileSync('sample.model', 'utf8'))
let result = model({
id: 1337,
created: new Date(),
name: 'Glen Danzig',
accountType: 'awesome'
})
```
### output
The result will be an object that contains the final data, as well as a
`length` property which indicates how many rules were violated, and a rules
property containing information about the rules that were violated.
```js
{
data: {
id: 1337,
created: '2016-10-02T13:56:44.931Z',
name: 'Glen Danzig',
accountType: 'awesome'
},
length: 1,
rules: {
accountType: [{
validator: 'type',
message: 'Expected type [Boolean] but got type [String]'
}]
}
}
```