surql
v0.0.0
Published
Work in progress.
Downloads
62
Readme
Work in progress.
What problem does surql solve?
- Uses
jyon
for validation - Creates tables and writes surql (SurrealDB query language) using TypeScript functions
- Typed communication to the SurrealDB
import { JYON } from 'jyon'
import surql from 'surql/validators'
const y = new JYON({
validators: [..., surql /*{ recordid, ref, ... }*/]
})
export default y
import y from '$jyon'
import { table, db } from 'surql'
let user = y.recursive(self => y.object({
id: y.recordid('User'),
name: y.string().min(3),
bestFriend: y.ref(self)
}))
let User = table(user, {
pre: {
create: (data) => data
},
post: {
// Do something after User.validate()
validate: (data) => data
}
})
User.validate(...)
let select = User.select(...)
let select = User.select.only('User:1', ...)
// Typed result
db.query(select)
// or insert query into other queries for more advanced queries.
db.query(
[User.deepPartial(), `SELECT id, name FROM ${select}`],
[y.object({...}), `SELECT ...`], // custom validator for result
`SELECT ...` // no validation
)