# prisma-datamodel

> Transform prisma datamodel SDL into graphql-js SDL

Latest version **1.34.12** (published 2021-01-12) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install prisma-datamodel
pnpm add prisma-datamodel
yarn add prisma-datamodel
bun add prisma-datamodel
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.34.12 |
| Published | 2021-01-12 |
| First published | 2018-11-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 204.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Emanuel Jöbstl |
| Maintainers | timsuchanek |

## Links

- npm: https://www.npmjs.com/package/prisma-datamodel
- npm.io page: https://npm.io/package/prisma-datamodel

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [graphql](https://npm.io/package/graphql.md) ^14.3.0
- [popsicle](https://npm.io/package/popsicle.md) 10
- [pluralize](https://npm.io/package/pluralize.md) ^7.0.0

## Recent versions

- 1.34.12 (latest) — 2021-01-12
- 1.36.0-alpha.11 (alpha) — 2019-06-14
- 1.36.0-test.2 (test) — 2019-06-08
- 1.35.0-beta (beta) — 2019-05-29
- 1.34.11 — 2021-01-12
- 1.34.10 — 2019-10-14
- 1.34.8 — 2019-08-29
- 1.34.7 — 2019-08-26
- 1.34.6 — 2019-08-20
- 1.34.5 — 2019-08-09
- 1.34.3 — 2019-07-24
- 1.30.5 — 2019-07-23
- 1.34.2 — 2019-07-19
- 1.34.1 — 2019-07-07
- 1.36.0-alpha.10 — 2019-06-13
- … 330 more at https://npm.io/package/prisma-datamodel/versions

## README

# prisma-datamodel

The Prisma Datamodel package forms the foundation of all datamodel related tasks in the CLI.

### Components

- Data structures to represent datamodels in memory: `ISDL`, `IGQLType`, `IGQLField`. These data structures are documented inline. The data structures might be self referencing, and all operations in this library guarantee to keep the references valid.
- Constants for known primitive types: `TypeIdentifier`, `TypeIdentifiers`
- Classes to parse data models from strings into the internal format: `Parser`, with the factory class`DefaultParser`
- Classes to render data models to strings, from the internal format: `Renderer`, with the factory class `Default Renderer`
- Auxiliary functions: `cloneSchema` to safely clone an `ISDL`structure, `toposort`to sort a datamodel in topological order.

### Different Database Types

When creating a parser or renderer, a flag that indicates the database type has to be passed. The internal representation is guaranteed to be consistent between different databases. It is possible to parse a mongo schema and render a postgres schema without any transformations in between.

### Datamodel V1 vs. V1.1

The parser is capable of parsing both datamodel formats, and even models with mixed directives from both standards. For rendering, a flag can be passed which indicates the datamodel format to follow.

### Modifying a Model

The types `ISDL`, `IGQLType` and `IGQLField` are designed to allow convenient analysis and transformation. Most notably, they may contain circular references (for representing related types and indexes). Therefor, these types are **mutable**, and care has to be taken when modifying them, for example by cloning them using `cloneSchema`.

When adding or removing a type, it is important to also update all referring fields or indexes, otherwise other transformations or the rendering process might break.

### Usage

Basic example:

```typescript
const parser = DefaultParser.create(DatabaseType.mongo)
const model = parser.parse(datamodelAsString)

// Do something with the model
for (const type of model.types) {
  console.log(
    `${type.name} has ${type.fields.length} fields and ${
      type.indices.length
    } indexes`,
  )
}

const enableDatamodel1_1 = true
const renderer = DefaultRenderer.create(
  DatabaseType.postgres,
  enableDatamodel1_1,
)

const renderedAsString = renderer.render(model)
```

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