mirror of https://github.com/AMT-Cheif/drift.git
Support bytea sql literal in postgres (#2943)
This commit is contained in:
parent
37f120d287
commit
039838b2ba
|
@ -115,9 +115,17 @@ final class SqlTypes {
|
||||||
return (dart.millisecondsSinceEpoch ~/ 1000).toString();
|
return (dart.millisecondsSinceEpoch ~/ 1000).toString();
|
||||||
}
|
}
|
||||||
} else if (dart is Uint8List) {
|
} else if (dart is Uint8List) {
|
||||||
|
final String hexString = hex.encode(dart);
|
||||||
|
|
||||||
|
if (dialect == SqlDialect.postgres) {
|
||||||
|
// Postgres BYTEA hex format
|
||||||
|
// https://www.postgresql.org/docs/current/datatype-binary.html#DATATYPE-BINARY-BYTEA-HEX-FORMAT
|
||||||
|
return "'\\x$hexString'::bytea";
|
||||||
|
} else {
|
||||||
// BLOB literals are string literals containing hexadecimal data and
|
// BLOB literals are string literals containing hexadecimal data and
|
||||||
// preceded by a single "x" or "X" character. Example: X'53514C697465'
|
// preceded by a single "x" or "X" character. Example: X'53514C697465'
|
||||||
return "x'${hex.encode(dart)}'";
|
return "x'${hex.encode(dart)}'";
|
||||||
|
}
|
||||||
} else if (dart is DriftAny) {
|
} else if (dart is DriftAny) {
|
||||||
return mapToSqlLiteral(dart.rawSqlValue);
|
return mapToSqlLiteral(dart.rawSqlValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ void main() {
|
||||||
return row.read(expression)!;
|
return row.read(expression)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
group('custom types pass through', () {
|
void testWith<T extends Object>(CustomSqlType<T>? type, T value) {
|
||||||
void testWith<T extends Object>(CustomSqlType<T> type, T value) {
|
|
||||||
test('with variable', () async {
|
test('with variable', () async {
|
||||||
final variable = Variable(value, type);
|
final variable = Variable(value, type);
|
||||||
expect(await eval(variable), value);
|
expect(await eval(variable), value);
|
||||||
|
@ -39,6 +38,7 @@ void main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group('custom types pass through', () {
|
||||||
group('uuid', () => testWith(PgTypes.uuid, Uuid().v4obj()));
|
group('uuid', () => testWith(PgTypes.uuid, Uuid().v4obj()));
|
||||||
group(
|
group(
|
||||||
'interval',
|
'interval',
|
||||||
|
@ -60,6 +60,8 @@ void main() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('bytea', () => testWith(null, Uint8List.fromList([1, 2, 3, 4, 5])));
|
||||||
|
|
||||||
test('compare datetimes', () async {
|
test('compare datetimes', () async {
|
||||||
final time = DateTime.now();
|
final time = DateTime.now();
|
||||||
final before = Variable(
|
final before = Variable(
|
||||||
|
|
Loading…
Reference in New Issue