Skip to content
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

Add batch support and keyword case support for sql #475

Merged
merged 1 commit into from
Oct 23, 2022

Conversation

snuyanzin
Copy link
Collaborator

@snuyanzin snuyanzin commented Oct 23, 2022

The PR adds support for batch insert, e.g.

Faker faker = new Faker();
Schema<String, String> schema =
    Schema.of(field("firstName", () -> faker.name().firstName()),
        field("lastName", () -> faker.name().lastName()));
SqlTransformer<String> transformer =
    new SqlTransformer.SqlTransformerBuilder<String>()
        .batch(true).dialect(SqlDialect.POSTGRES).build();
final int limit = 5;
String output = transformer.generate(schema, limit);
System.out.println(output);

will result in something like

INSERT INTO "MyTable" ("firstName", "lastName")
VALUES ('Lyman', 'Kessler'),
       ('Loriann', 'Lowe'),
       ('Gaynell', 'Blick'),
       ('Kallie', 'Kohler'),
       ('Rosalee', 'Armstrong');

Also keyword case support e.g.

Faker faker = new Faker();
Schema<String, String> schema =
    Schema.of(field("firstName", () -> faker.name().firstName()),
        field("lastName", () -> faker.name().lastName()));
SqlTransformer<String> transformer =
    new SqlTransformer.SqlTransformerBuilder<String>()
        .keywordUpperCase(false)
        .dialect(SqlDialect.POSTGRES).build();
System.out.println(transformer.generate(schema, 1));

will print sql with keywords in lowercase

insert into "MyTable" ("firstName", "lastName") values ('Mohammad', 'White');

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2022

Codecov Report

Merging #475 (531d3fb) into main (f5304e0) will increase coverage by 0.10%.
The diff coverage is 77.41%.

@@             Coverage Diff              @@
##               main     #475      +/-   ##
============================================
+ Coverage     93.08%   93.19%   +0.10%     
- Complexity     2111     2123      +12     
============================================
  Files           233      233              
  Lines          4398     4421      +23     
  Branches        452      458       +6     
============================================
+ Hits           4094     4120      +26     
+ Misses          190      188       -2     
+ Partials        114      113       -1     
Impacted Files Coverage Δ
...net/datafaker/transformations/JsonTransformer.java 84.37% <25.00%> (-3.67%) ⬇️
...java/net/datafaker/transformations/SqlDialect.java 94.44% <75.00%> (-5.56%) ⬇️
.../net/datafaker/transformations/SqlTransformer.java 82.72% <85.71%> (+10.56%) ⬆️
...ain/java/net/datafaker/transformations/Casing.java 100.00% <100.00%> (ø)
.../net/datafaker/transformations/CsvTransformer.java 93.10% <100.00%> (ø)
.../main/java/net/datafaker/service/FakerContext.java 87.17% <0.00%> (+2.56%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@snuyanzin snuyanzin merged commit f6dc9d7 into datafaker-net:main Oct 23, 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