Skip to content

Add support of sql dialect while sql generation #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

snuyanzin
Copy link
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
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