Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prisma-datamodel

Package Overview
Dependencies
Maintainers
1
Versions
345
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-datamodel

Transform prisma datamodel SDL into graphql-js SDL

  • 1.35.0-alpha.1
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
decreased by-48.52%
Maintainers
1
Weekly downloads
 
Created
Source

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 classDefaultParser
  • 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 ISDLstructure, toposortto 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:

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)

FAQs

Package last updated on 28 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc