Skip to content

Commit

Permalink
feat: parse datasource and generator
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmezencio authored and AhmedElywa committed Dec 14, 2024
1 parent da0610a commit 1c1c622
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/schema/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export class ConvertSchemaToObject extends PrismaReader {
schemaObject: SchemaObject = {
models: [],
enums: [],
dataSource: undefined,
generators: [],
};

constructor(protected path: string) {
Expand All @@ -14,6 +16,9 @@ export class ConvertSchemaToObject extends PrismaReader {
run() {
this.getModels();
this.getEnums();
this.getDataSource();
this.getGenerators();

return this.schemaObject;
}

Expand Down Expand Up @@ -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] || '',
};
});
}
}
}

0 comments on commit 1c1c622

Please sign in to comment.