Skip to content

Commit

Permalink
return generated dbml, make fs optional
Browse files Browse the repository at this point in the history
There are two noticeable interface changes
- `Options.out` has become optional instead of required
- return types of generate fns have become `string` instead of `void`

Both are non-breaking changes.

Resolves #8
  • Loading branch information
cometkim committed Nov 24, 2023
1 parent 09d7771 commit 4b65e06
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/generators/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class MySqlGenerator extends BaseGenerator<MySqlSchema, AnyMySqlColumn> {
}
}

export function mysqlGenerate<T>(options: Options<T>) {
export function mysqlGenerate<T>(options: Options<T>): string {
options.relational ||= false;
const dbml = new MySqlGenerator(options.schema as MySqlSchema, options.relational).generate();
writeDBMLFile(dbml, options.out);
options.out && writeDBMLFile(dbml, options.out);
return dbml;
}
5 changes: 3 additions & 2 deletions src/generators/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class PgGenerator extends BaseGenerator<PgSchema, AnyPgColumn> {
}
}

export function pgGenerate<T>(options: Options<T>) {
export function pgGenerate<T>(options: Options<T>): string {
options.relational ||= false;
const dbml = new PgGenerator(options.schema as PgSchema, options.relational).generate();
writeDBMLFile(dbml, options.out);
options.out && writeDBMLFile(dbml, options.out);
return dbml;
}
5 changes: 3 additions & 2 deletions src/generators/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class SQLiteGenerator extends BaseGenerator<SQLiteSchema, AnySQLiteColumn> {
}
}

export function sqliteGenerate<T>(options: Options<T>) {
export function sqliteGenerate<T>(options: Options<T>): string {
options.relational ||= false;
const dbml = new SQLiteGenerator(options.schema as SQLiteSchema, options.relational).generate();
writeDBMLFile(dbml, options.out);
options.out && writeDBMLFile(dbml, options.out);
return dbml;
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type AnyBuilder = {
};
export type Options<Schema> = {
schema: Schema;
out: string;
out?: string;
relational?: boolean;
};

Expand Down

0 comments on commit 4b65e06

Please sign in to comment.