single-source-of-truth
Version:
<div align='center'> <h1><strong>single-source-of-truth</strong></h1> <i>Use ArkType schemas to generate your Prisma schema</i><br> <code>pnpm add truth@npm:single-source-of-truth arktype</code> </div>
72 lines (59 loc) • 2.08 kB
Markdown
<div align='center'>
<h1><strong>single-source-of-truth</strong></h1>
<i>Use ArkType schemas to generate your Prisma schema</i><br>
<code>pnpm add truth@npm:single-source-of-truth arktype</code>
</div>
<div align='center'>
<img alt='package version' src='https://img.shields.io/npm/v/single-source-of-truth?label=version'>
<img alt='total downloads' src='https://img.shields.io/npm/dt/single-source-of-truth'>
<br>
<a href='https://github.com/apteryxxyz/single-source-of-truth'><img alt='single-source-of-truth repo stars' src='https://img.shields.io/github/stars/apteryxxyz/single-source-of-truth?style=social'></a>
<a href='https://github.com/apteryxxyz'><img alt='apteryxxyz followers' src='https://img.shields.io/github/followers/apteryxxyz?style=social'></a>
<a href='https://discord.gg/g5wz46CXNK'><img src='https://discordapp.com/api/guilds/829836158007115806/widget.png?style=shield' alt='discord shield'/></a>
</div>
```sh
pnpm add truth@npm:single-source-of-truth arktype
```
```ts
// src/shapes.ts
import { field, model, relation } from 'arktype';
export const User = model({
id: field('string').id_(),
name: field('string | null'),
posts: () => relation(() => Post.array()),
});
export type User = typeof User.infer;
// ^? { id: string, name: string | null }
export const Post = model({
id: field('string').id_(),
authorId: field('string'),
title: field('string'),
author: () => relation(() => User).reference('authorId', 'id'),
});
export type Post = typeof Post.infer;
// ^? { id: string, authorId: string, title: string }
```
```ts
// truth.config.ts
import { defineConfig } from 'truth/config';
export default defineConfig(({ registry, arktype, prisma }) => {
await arktype.import(registry, './src/shapes.ts');
await prisma.export(registry, './prisma/generated.prisma');
});
```
```sh
truth
```
```prisma
model User {
id String @id
name String?
posts Post[]
}
model Post {
id String @id
authorId String
title String
author User @relation(fields: [authorId], references: [id])
}
```