# effect-db-schema

Latest version **0.0.57** (published 2024-09-06) · 0 weekly downloads

## Install

```sh
npm install effect-db-schema
pnpm add effect-db-schema
yarn add effect-db-schema
bun add effect-db-schema
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.57 |
| Published | 2024-09-06 |
| First published | 2023-10-26 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 520.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | schickling |

## Links

- npm: https://www.npmjs.com/package/effect-db-schema
- npm.io page: https://npm.io/package/effect-db-schema

## Dependencies (1)

- [dprint-node](https://npm.io/package/dprint-node.md) ^1.0.8

## Recent versions

- 0.0.57 (latest) — 2024-09-06
- 0.0.58-dev.9 (dev) — 2024-10-31
- 0.0.58-dev.8 — 2024-10-31
- 0.0.58-dev.7 — 2024-10-31
- 0.0.58-dev.6 — 2024-09-11
- 0.0.58-dev.5 — 2024-09-07
- 0.0.58-dev.4 — 2024-09-07
- 0.0.58-dev.3 — 2024-09-07
- 0.0.58-dev.2 — 2024-09-07
- 0.0.58-dev.1 — 2024-09-07
- 0.0.58-dev.0 — 2024-09-07
- 0.0.57-dev.8 — 2024-09-06
- 0.0.57-dev.7 — 2024-09-06
- 0.0.57-dev.6 — 2024-09-06
- 0.0.57-dev.5 — 2024-09-06
- … 99 more at https://npm.io/package/effect-db-schema/versions

## README

# Requirements

<!-- - Being able to map a Effect Schema to a db schema -->

- 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

```ts
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

```bash
dbcli codegen --schema ./src/db-schema.ts --output ./src/drizzle-db-schema.ts
```

```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

---
_Source: https://npm.io/package/effect-db-schema · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
