Skip to content

Commit 440817b

Browse files
feat: add support for bpchar Postgres type
1 parent 9761e78 commit 440817b

24 files changed

Lines changed: 683 additions & 282 deletions

File tree

docs/04_Postgres.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ we consider support for the different data types separately for batch inserts an
3434
| time with time zone |||
3535
| interval |||
3636
| char |||
37-
| bpchar | | |
37+
| bpchar | | |
3838
| varchar, character varying |||
3939
| text |||
4040
| bytea |||

end2end/EndToEndScaffold/Templates/PostgresTests.cs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ public static class PostgresTests
1010
{
1111
Impl = $$"""
1212
[Test]
13-
[TestCase("E", "It takes a nation of millions to hold us back", "Rebel Without a Pause", "Prophets of Rage")]
14-
[TestCase(null, null, null, null)]
13+
[TestCase("E", "It takes a nation of millions to hold us back", "Rebel Without a Pause", "Master of Puppets", "Prophets of Rage")]
14+
[TestCase(null, null, null, null, null)]
1515
public async Task TestPostgresStringTypes(
1616
string cChar,
1717
string cVarchar,
1818
string cCharacterVarying,
19+
string cBpchar,
1920
string cText)
2021
{
2122
await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs
2223
{
2324
CChar = cChar,
2425
CVarchar = cVarchar,
2526
CCharacterVarying = cCharacterVarying,
27+
CBpchar = cBpchar,
2628
CText = cText,
2729
});
2830
@@ -31,14 +33,21 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs
3133
CChar = cChar,
3234
CVarchar = cVarchar,
3335
CCharacterVarying = cCharacterVarying,
36+
CBpchar = cBpchar,
3437
CText = cText,
3538
};
36-
var actual = await QuerySql.GetPostgresTypes();
3739
38-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CChar, Is.EqualTo(expected.CChar));
39-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CVarchar, Is.EqualTo(expected.CVarchar));
40-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CCharacterVarying, Is.EqualTo(expected.CCharacterVarying));
41-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CText, Is.EqualTo(expected.CText));
40+
var actual = await QuerySql.GetPostgresTypes();
41+
AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}});
42+
43+
void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y)
44+
{
45+
Assert.That(x.CChar, Is.EqualTo(y.CChar));
46+
Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar));
47+
Assert.That(x.CCharacterVarying, Is.EqualTo(y.CCharacterVarying));
48+
Assert.That(x.CBpchar?.Trim(), Is.EqualTo(y.CBpchar?.Trim()));
49+
Assert.That(x.CText, Is.EqualTo(y.CText));
50+
}
4251
}
4352
"""
4453
},
@@ -191,13 +200,14 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs
191200
{
192201
Impl = $$"""
193202
[Test]
194-
[TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Never Mind the Bollocks...")]
195-
[TestCase(10, null, null, null, null)]
203+
[TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Yoshimi Battles the Pink Robots", "Never Mind the Bollocks...")]
204+
[TestCase(10, null, null, null, null, null)]
196205
public async Task TestStringCopyFrom(
197206
int batchSize,
198207
string cChar,
199208
string cVarchar,
200209
string cCharacterVarying,
210+
string cBpchar,
201211
string cText)
202212
{
203213
var batchArgs = Enumerable.Range(0, batchSize)
@@ -206,6 +216,7 @@ public async Task TestStringCopyFrom(
206216
CChar = cChar,
207217
CVarchar = cVarchar,
208218
CCharacterVarying = cCharacterVarying,
219+
CBpchar = cBpchar,
209220
CText = cText
210221
})
211222
.ToList();
@@ -216,15 +227,21 @@ public async Task TestStringCopyFrom(
216227
CChar = cChar,
217228
CVarchar = cVarchar,
218229
CCharacterVarying = cCharacterVarying,
230+
CBpchar = cBpchar,
219231
CText = cText
220232
};
221233
var actual = await QuerySql.GetPostgresTypesCnt();
222-
223-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.Cnt, Is.EqualTo(expected.Cnt));
224-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CChar, Is.EqualTo(expected.CChar));
225-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CVarchar, Is.EqualTo(expected.CVarchar));
226-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CCharacterVarying, Is.EqualTo(expected.CCharacterVarying));
227-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CText, Is.EqualTo(expected.CText));
234+
AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}});
235+
236+
void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y)
237+
{
238+
Assert.That(x.Cnt, Is.EqualTo(y.Cnt));
239+
Assert.That(x.CChar, Is.EqualTo(y.CChar));
240+
Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar));
241+
Assert.That(x.CCharacterVarying, Is.EqualTo(y.CCharacterVarying));
242+
Assert.That(x.CBpchar?.Trim(), Is.EqualTo(y.CBpchar?.Trim()));
243+
Assert.That(x.CText, Is.EqualTo(y.CText));
244+
}
228245
}
229246
"""
230247
},

end2end/EndToEndTests/NpgsqlDapperTester.generated.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,29 @@ public async Task TestNargNotNull()
290290
}
291291

292292
[Test]
293-
[TestCase("E", "It takes a nation of millions to hold us back", "Rebel Without a Pause", "Prophets of Rage")]
294-
[TestCase(null, null, null, null)]
295-
public async Task TestPostgresStringTypes(string cChar, string cVarchar, string cCharacterVarying, string cText)
293+
[TestCase("E", "It takes a nation of millions to hold us back", "Rebel Without a Pause", "Master of Puppets", "Prophets of Rage")]
294+
[TestCase(null, null, null, null, null)]
295+
public async Task TestPostgresStringTypes(string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText)
296296
{
297-
await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CText = cText, });
297+
await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, });
298298
var expected = new QuerySql.GetPostgresTypesRow
299299
{
300300
CChar = cChar,
301301
CVarchar = cVarchar,
302302
CCharacterVarying = cCharacterVarying,
303+
CBpchar = cBpchar,
303304
CText = cText,
304305
};
305306
var actual = await QuerySql.GetPostgresTypes();
306-
Assert.That(actual.CChar, Is.EqualTo(expected.CChar));
307-
Assert.That(actual.CVarchar, Is.EqualTo(expected.CVarchar));
308-
Assert.That(actual.CCharacterVarying, Is.EqualTo(expected.CCharacterVarying));
309-
Assert.That(actual.CText, Is.EqualTo(expected.CText));
307+
AssertSingularEquals(expected, actual);
308+
void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y)
309+
{
310+
Assert.That(x.CChar, Is.EqualTo(y.CChar));
311+
Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar));
312+
Assert.That(x.CCharacterVarying, Is.EqualTo(y.CCharacterVarying));
313+
Assert.That(x.CBpchar?.Trim(), Is.EqualTo(y.CBpchar?.Trim()));
314+
Assert.That(x.CText, Is.EqualTo(y.CText));
315+
}
310316
}
311317

312318
[Test]
@@ -414,26 +420,32 @@ private static void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow expect
414420
}
415421

416422
[Test]
417-
[TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Never Mind the Bollocks...")]
418-
[TestCase(10, null, null, null, null)]
419-
public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarchar, string cCharacterVarying, string cText)
423+
[TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Yoshimi Battles the Pink Robots", "Never Mind the Bollocks...")]
424+
[TestCase(10, null, null, null, null, null)]
425+
public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText)
420426
{
421-
var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CText = cText }).ToList();
427+
var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList();
422428
await QuerySql.InsertPostgresTypesBatch(batchArgs);
423429
var expected = new QuerySql.GetPostgresTypesCntRow
424430
{
425431
Cnt = batchSize,
426432
CChar = cChar,
427433
CVarchar = cVarchar,
428434
CCharacterVarying = cCharacterVarying,
435+
CBpchar = cBpchar,
429436
CText = cText
430437
};
431438
var actual = await QuerySql.GetPostgresTypesCnt();
432-
Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt));
433-
Assert.That(actual.CChar, Is.EqualTo(expected.CChar));
434-
Assert.That(actual.CVarchar, Is.EqualTo(expected.CVarchar));
435-
Assert.That(actual.CCharacterVarying, Is.EqualTo(expected.CCharacterVarying));
436-
Assert.That(actual.CText, Is.EqualTo(expected.CText));
439+
AssertSingularEquals(expected, actual);
440+
void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y)
441+
{
442+
Assert.That(x.Cnt, Is.EqualTo(y.Cnt));
443+
Assert.That(x.CChar, Is.EqualTo(y.CChar));
444+
Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar));
445+
Assert.That(x.CCharacterVarying, Is.EqualTo(y.CCharacterVarying));
446+
Assert.That(x.CBpchar?.Trim(), Is.EqualTo(y.CBpchar?.Trim()));
447+
Assert.That(x.CText, Is.EqualTo(y.CText));
448+
}
437449
}
438450

439451
[Test]

end2end/EndToEndTests/NpgsqlTester.generated.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,29 @@ public async Task TestNargNotNull()
290290
}
291291

292292
[Test]
293-
[TestCase("E", "It takes a nation of millions to hold us back", "Rebel Without a Pause", "Prophets of Rage")]
294-
[TestCase(null, null, null, null)]
295-
public async Task TestPostgresStringTypes(string cChar, string cVarchar, string cCharacterVarying, string cText)
293+
[TestCase("E", "It takes a nation of millions to hold us back", "Rebel Without a Pause", "Master of Puppets", "Prophets of Rage")]
294+
[TestCase(null, null, null, null, null)]
295+
public async Task TestPostgresStringTypes(string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText)
296296
{
297-
await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CText = cText, });
297+
await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, });
298298
var expected = new QuerySql.GetPostgresTypesRow
299299
{
300300
CChar = cChar,
301301
CVarchar = cVarchar,
302302
CCharacterVarying = cCharacterVarying,
303+
CBpchar = cBpchar,
303304
CText = cText,
304305
};
305306
var actual = await QuerySql.GetPostgresTypes();
306-
Assert.That(actual.Value.CChar, Is.EqualTo(expected.CChar));
307-
Assert.That(actual.Value.CVarchar, Is.EqualTo(expected.CVarchar));
308-
Assert.That(actual.Value.CCharacterVarying, Is.EqualTo(expected.CCharacterVarying));
309-
Assert.That(actual.Value.CText, Is.EqualTo(expected.CText));
307+
AssertSingularEquals(expected, actual.Value);
308+
void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y)
309+
{
310+
Assert.That(x.CChar, Is.EqualTo(y.CChar));
311+
Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar));
312+
Assert.That(x.CCharacterVarying, Is.EqualTo(y.CCharacterVarying));
313+
Assert.That(x.CBpchar?.Trim(), Is.EqualTo(y.CBpchar?.Trim()));
314+
Assert.That(x.CText, Is.EqualTo(y.CText));
315+
}
310316
}
311317

312318
[Test]
@@ -414,26 +420,32 @@ private static void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow expect
414420
}
415421

416422
[Test]
417-
[TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Never Mind the Bollocks...")]
418-
[TestCase(10, null, null, null, null)]
419-
public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarchar, string cCharacterVarying, string cText)
423+
[TestCase(100, "z", "Sex Pistols", "Anarchy in the U.K", "Yoshimi Battles the Pink Robots", "Never Mind the Bollocks...")]
424+
[TestCase(10, null, null, null, null, null)]
425+
public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText)
420426
{
421-
var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CText = cText }).ToList();
427+
var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList();
422428
await QuerySql.InsertPostgresTypesBatch(batchArgs);
423429
var expected = new QuerySql.GetPostgresTypesCntRow
424430
{
425431
Cnt = batchSize,
426432
CChar = cChar,
427433
CVarchar = cVarchar,
428434
CCharacterVarying = cCharacterVarying,
435+
CBpchar = cBpchar,
429436
CText = cText
430437
};
431438
var actual = await QuerySql.GetPostgresTypesCnt();
432-
Assert.That(actual.Value.Cnt, Is.EqualTo(expected.Cnt));
433-
Assert.That(actual.Value.CChar, Is.EqualTo(expected.CChar));
434-
Assert.That(actual.Value.CVarchar, Is.EqualTo(expected.CVarchar));
435-
Assert.That(actual.Value.CCharacterVarying, Is.EqualTo(expected.CCharacterVarying));
436-
Assert.That(actual.Value.CText, Is.EqualTo(expected.CText));
439+
AssertSingularEquals(expected, actual.Value);
440+
void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y)
441+
{
442+
Assert.That(x.Cnt, Is.EqualTo(y.Cnt));
443+
Assert.That(x.CChar, Is.EqualTo(y.CChar));
444+
Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar));
445+
Assert.That(x.CCharacterVarying, Is.EqualTo(y.CCharacterVarying));
446+
Assert.That(x.CBpchar?.Trim(), Is.EqualTo(y.CBpchar?.Trim()));
447+
Assert.That(x.CText, Is.EqualTo(y.CText));
448+
}
437449
}
438450

439451
[Test]

0 commit comments

Comments
 (0)