npm.io
0.0.57 • Published 1 year ago

effect-db-schema

Licence
Version
0.0.57
Deps
1
Size
521 kB
Vulns
0
Weekly
0

Requirements

  • Being able to reuse a Effect Schema to a db schema through a magic function
  • We want to be able to map multiple flavors, including representing a struct just as a string column, or a json column
  • The system takes care of transforming the struct into the db shape and back
  • Concrete DB flavours (e.g. SQLite, Postgres, etc) are implemented separately

High-level API

export const User = Schema.Struct({
  id: Schema.String,
  name: Schema.String,
})

const user: User = Schema.decodeSnyc({
  id: 'bob',
  name: 'Bob',
})(User)

// save user
await magicDbFunction.persist(user)

// get user
const myUser: User = await magicDbFunction.get(user)

tableFromStruct: DB Table derived from Struct Schema

  • Caveats
    • Only works for structs
    • No control of number types (always uses reals/floats)
Codegen
dbcli codegen --schema ./src/db-schema.ts --output ./src/drizzle-db-schema.ts
import {gen} from 'framework'

gen(struct, './lol.ts')

MVP

Contributors

  • Thanks a lot to @timsuchanek for contributing the initial version of the Drizzle codegen tool