@livestore/db-schema
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @livestore/db-schema

Weekly Downloads

3,131

Version

0.1.0

License

none

Unpacked Size

548 kB

Total Files

80

Last publish

Collaborators

  • livestore-bot
  • schickling