Registry / database / prisma-schema-dsl

prisma-schema-dsl

JSON →
library2.2.0jsnpmunverified

A JavaScript/TypeScript library for programmatically building and printing Prisma Schema DSL ASTs. Current stable version 2.2.0 allows creating enums, models, fields, and data sources with validation and type safety. Exports a print() function that formats the AST into a valid Prisma schema file using prisma-format. Key differentiator: provides a type-safe builder pattern instead of string manipulation, with full TypeScript support. Active development on GitHub under Amplication.

npm install prisma-schema-dsl
INSTALL
IMPORT
SIG · PRISMA-SCHEMA-DSL
P
prisma-schema-dsl
databasejavascriptv2.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createSchema
import { createSchema } from 'prisma-schema-dsl'
const createSchema = require('prisma-schema-dsl').createSchema
Library is ESM-only – named imports require ES module environment. CJS require() will fail.
Schema
import type { Schema } from 'prisma-schema-dsl'
TypeScript users should use `import type` for compile-time only types as the library ships types. Alternatively use `import { Schema }` if runtime value is needed (but it's only a type).
print
import { print } from 'prisma-schema-dsl'
import print from 'prisma-schema-dsl'
print() is a named export, not a default export. Default import will be undefined.

Demonstrates building a complete Prisma schema with enum, model, scalar fields, and data source, then printing the result.

import { createSchema, createModel, createScalarField, createEnum, print } from 'prisma-schema-dsl'; async function main() { const statusEnum = createEnum('Status', ['ACTIVE', 'INACTIVE']); const fields = [ createScalarField('id', 'Int', false, true, true, true, false, { autoincrement: true }), createScalarField('email', 'String', false, true), createScalarField('name', 'String', false, false), ]; const model = createModel('User', fields); const schema = createSchema([model], { provider: 'postgresql', url: 'env("DATABASE_URL")' }); const schemaString = await print(schema); console.log(schemaString); } main().catch(console.error);
Debug
Known issues
gotchaprint() is async and returns a Promise – forgetting await will result in a Promise object instead of schema string
fix
Use await print(schema) or .then() to get the string.
affects: >=1.0.0
gotchaField names and model/enum names are validated; passing invalid names throws an error at runtime
fix
Ensure names are valid Prisma identifiers: start with letter or underscore, alphanumeric/underscore only.
affects: >=1.0.0
deprecatedcreateDataSource signature changed in v2.0.0; old signature with positional args is deprecated
fix
Use the object parameter: createDataSource({ name: 'db', provider: 'postgresql', url: '...' })
affects: >=2.0.0
gotchaESM-only package; using require() in CommonJS will throw 'ERR_REQUIRE_ESM'
fix
Switch to ES modules by setting type: module in package.json, or use dynamic import() with .mjs extension.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: print(...).then is not a function
Assuming print returns a string instead of a Promise (missing await)
fix
Add await before print(schema) or use .then() on the returned Promise.
ERR_REQUIRE_ESM
Trying to require() an ESM-only module from CommonJS
fix
Use import() or switch your project to ES modules.
Error: Invalid identifier: ...
Invalid name passed to createModel, createEnum, etc.
fix
Update name to follow Prisma identifier rules (letters, digits, underscores; cannot start with digit).
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
prisma-formatoptionalUnderlying formatter used by print() to format the generated schema string
Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
prisma-schema-dsl — npm install prisma-schema-dsl · libregistry