From 1c1c62207a5fff7375254813a3dbc4a27e239787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Mez=C3=AAncio?= Date: Tue, 12 Nov 2024 17:47:43 +0000 Subject: [PATCH] feat: parse `datasource` and `generator` --- packages/schema/src/json.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/schema/src/json.ts b/packages/schema/src/json.ts index b0eb0790..afa8a591 100644 --- a/packages/schema/src/json.ts +++ b/packages/schema/src/json.ts @@ -5,6 +5,8 @@ export class ConvertSchemaToObject extends PrismaReader { schemaObject: SchemaObject = { models: [], enums: [], + dataSource: undefined, + generators: [], }; constructor(protected path: string) { @@ -14,6 +16,9 @@ export class ConvertSchemaToObject extends PrismaReader { run() { this.getModels(); this.getEnums(); + this.getDataSource(); + this.getGenerators(); + return this.schemaObject; } @@ -89,4 +94,26 @@ export class ConvertSchemaToObject extends PrismaReader { } } } + + private getDataSource() { + if (this.dataSource) { + this.schemaObject.dataSource = this.dataSource.map((dataSource) => { + return { + provider: dataSource.match(/provider\s+=\s+"(\w+)"/)?.[1] || '', + url: dataSource.match(/url\s+=\s+(.+)/)?.[1] || '', + }; + })[0]; + } + } + + private getGenerators() { + if (this.generators) { + this.schemaObject.generators = this.generators.map((generator) => { + return { + name: generator.match(/generator\s+(\w+)/)?.[1] || '', + provider: generator.match(/provider\s+=\s+"(.+)"/)?.[1] || '', + }; + }); + } + } }