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

@mrleebo/prisma-ast

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mrleebo/prisma-ast

This library uses an abstract syntax tree to parse schema.prisma files into an object in JavaScript. It is similar to [@prisma/sdk](https://github.com/prisma/prisma/tree/master/src/packages/sdk) except that it preserves comments and model attributes.

  • 0.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
153K
decreased by-4.57%
Maintainers
1
Weekly downloads
 
Created

What is @mrleebo/prisma-ast?

@mrleebo/prisma-ast is an npm package designed to parse and manipulate Prisma schema files. It provides an Abstract Syntax Tree (AST) representation of Prisma schema files, allowing developers to programmatically read, modify, and generate Prisma schema definitions.

What are @mrleebo/prisma-ast's main functionalities?

Parsing Prisma Schema

This feature allows you to parse a Prisma schema string into an AST. The code sample demonstrates how to parse a simple Prisma schema and output the resulting AST.

const { parseSchema } = require('@mrleebo/prisma-ast');
const schema = `
model User {
  id    Int     @id @default(autoincrement())
  name  String
}
`;
const ast = parseSchema(schema);
console.log(JSON.stringify(ast, null, 2));

Modifying Prisma Schema

This feature allows you to modify an existing Prisma schema by manipulating its AST. The code sample shows how to add a new field to the User model and then print the updated schema.

const { parseSchema, printSchema } = require('@mrleebo/prisma-ast');
let schema = `
model User {
  id    Int     @id @default(autoincrement())
  name  String
}
`;
let ast = parseSchema(schema);
ast.declarations[0].fields.push({
  name: 'email',
  type: 'String',
  attributes: []
});
schema = printSchema(ast);
console.log(schema);

Generating Prisma Schema

This feature allows you to generate a Prisma schema from an AST. The code sample demonstrates how to create an AST for a simple User model and then generate the corresponding Prisma schema string.

const { printSchema } = require('@mrleebo/prisma-ast');
const ast = {
  type: 'schema',
  declarations: [
    {
      type: 'model',
      name: 'User',
      fields: [
        { name: 'id', type: 'Int', attributes: [{ type: 'attribute', name: 'id' }, { type: 'attribute', name: 'default', args: [{ type: 'function', name: 'autoincrement' }] }] },
        { name: 'name', type: 'String', attributes: [] }
      ]
    }
  ]
};
const schema = printSchema(ast);
console.log(schema);

Other packages similar to @mrleebo/prisma-ast

FAQs

Package last updated on 24 Apr 2021

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