Skip to content

Add support of sql dialect while sql generation#445

Merged
snuyanzin merged 1 commit intodatafaker-net:mainfrom
snuyanzin:sql
Oct 18, 2022
Merged

Add support of sql dialect while sql generation#445
snuyanzin merged 1 commit intodatafaker-net:mainfrom
snuyanzin:sql

Conversation

@snuyanzin
Copy link
Copy Markdown
Collaborator

The PR adds supports of several SQL dialects
e.g. for postgres there is " as a sql quote identifier , for MSSQL it's [], for some other dbs it's `
e.g. for postgresql

INSERT INTO "MyTable" ("key") VALUES ('value');
INSERT INTO "MyTable" ("number") VALUES (123);
INSERT INTO "MyTable" ("number") VALUES (123.0);

for MSSQL

INSERT INTO [MyTable] ([number]) VALUES (123.123);
INSERT INTO [MyTable] ([boolean]) VALUES (true);

to generate the following code could be used

SqlTransformer<?> transformer = new SqlTransformer.SqlTransformerBuilder().dialect(SqlDialect.MSSQL).build();
transformer.generate(Schema.of(field("number", () -> 123.123)), 1);

possible output

INSERT INTO [MyTable] ([number]) VALUES (123.123);

same for postgres

SqlTransformer<?> transformer = new SqlTransformer.SqlTransformerBuilder().dialect(SqlDialect.POSTGRES).build();
transformer.generate(Schema.of(field("number", () -> 123.123)), 1);

output

INSERT INTO "MyTable" ("number") VALUES (123.123);

@bodiam
Copy link
Copy Markdown
Contributor

bodiam commented Oct 17, 2022

That's fancy! Great work!

@snuyanzin snuyanzin merged commit 35651df into datafaker-net:main Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants