Introduction:
prisma-schema-generator
is a package that provides a set of functions to programmatically generate a Prisma Schema file. With this package, you can easily generate the schema.prisma
file that define your database schema, without manually writing it.
Disclaimer: This package is a fork of the original prisma-schema-dsl repository, which was developed by the Amplication team. The code present in this repository was modified and amended to my needs.
API:
The following functions are available in the prisma-schema-generator
package:
function print(options: { schema: Schema }): Promise<string>;
Prints Prisma schema file from AST. The schema is formatted using prisma-format.
function createSchema(options: {
models: Model[];
enums: Enum[];
dataSource?: DataSource;
generators?: Generator[];
views?: View[];
}): Schema;
function createEnum(options: {
name: string;
values: string[];
documentation?: string;
}): Enum;
function createModel(options: {
name: string;
fields: Array<ScalarField | ObjectField>;
documentation?: string;
map?: string;
indexes?: Array<Index>;
fullTextIndexes?: Array<FullTextIndex>;
}): Model;
function createScalarField(options: {
name: string;
type: ScalarType;
isList?: boolean;
isRequired?: boolean;
isUnique?: boolean;
isId?: boolean;
isUpdatedAt?: boolean;
defaultValue?: ScalarFieldDefault;
documentation?: string;
isForeignKey?: boolean;
}): ScalarField;
function createObjectField(options: {
name: string;
type: string;
isList?: boolean;
isRequired?: boolean;
relationName?: string | null;
relationFields?: string[];
relationReferences?: string[];
relationOnDelete?: ReferentialActions;
relationOnUpdate?: ReferentialActions;
documentation?: string;
}): ObjectField;
function createDataSource(options: {
name: string;
provider: DataSourceProvider;
url: string | DataSourceURLEnv;
relationMode?: DataSource["relationMode"];
}): DataSource;
function createGenerator(options: {
name: string;
provider: string;
output?: string | null;
binaryTargets?: string[];
previewFeatures?: Array<PreviewFeature>;
}): Generator;