Update to postgres 3.0.0

This commit is contained in:
Simon Binder 2023-11-15 11:35:45 +01:00
parent 1daf21280a
commit e19de7ce0a
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
6 changed files with 18 additions and 17 deletions

View File

@ -1,5 +1,7 @@
## 0.2.0
## 1.0.0
- __Breaking__: The interval type now expects `Interval` types from postgres
instead of `Duration` objects.
- Migrate to the stable v3 version of the `postgres` package.
## 0.1.0

View File

@ -1,11 +1,6 @@
`package:drift_postgres` extends [drift](https://drift.simonbinder.eu/) to support
talking to PostgreSQL databases by using the `postgres` package.
This package is currently in alpha. It uses preview APIs from the `postgres` packages,
which may require this package to be updated if there are breaking changes in that
package. Once these APIs from `postgres` are stabilized, a stable version of `drift_postgres`
will be released as well.
## Using this
For general notes on using drift, see [this guide](https://drift.simonbinder.eu/getting-started/).

View File

@ -40,7 +40,7 @@ final class PgTypes {
static const CustomSqlType<UuidValue> uuid = UuidType();
/// The `interval` type in Postgres.
static const CustomSqlType<Duration> interval = IntervalType();
static const CustomSqlType<pg.Interval> interval = IntervalType();
/// The `date` type in Postgres.
static const CustomSqlType<PgDate> date = DateType(

View File

@ -1,7 +1,7 @@
import 'package:drift/drift.dart';
import 'package:postgres/postgres.dart';
// ignore: implementation_imports
import 'package:postgres/src/text_codec.dart';
import 'package:postgres/src/types/text_codec.dart';
import 'package:uuid/uuid.dart';
class PostgresType<T extends Object> implements CustomSqlType<T> {
@ -43,7 +43,7 @@ class UuidType extends PostgresType<UuidValue> {
@override
UuidValue read(Object fromSql) {
return UuidValue(fromSql as String);
return UuidValue.fromString(fromSql as String);
}
}
@ -57,12 +57,12 @@ class PointType extends PostgresType<Point> {
}
}
class IntervalType extends PostgresType<Duration> {
class IntervalType extends PostgresType<Interval> {
const IntervalType() : super(type: Type.interval, name: 'interval');
@override
String mapToSqlLiteral(Duration dartValue) {
return "'${dartValue.inMicroseconds} microseconds'::interval";
String mapToSqlLiteral(Interval dartValue) {
return "'$dartValue'::interval";
}
}

View File

@ -1,6 +1,6 @@
name: drift_postgres
description: Postgres implementation and APIs for the drift database package.
version: 0.2.0-dev
version: 1.0.0
repository: https://github.com/simolus3/drift
homepage: https://drift.simonbinder.eu/docs/platforms/postgres/
issue_tracker: https://github.com/simolus3/drift/issues
@ -11,12 +11,12 @@ environment:
dependencies:
collection: ^1.16.0
drift: ^2.0.0
postgres: ^3.0.0-beta.1
postgres: ^3.0.0
meta: ^1.8.0
uuid: ^4.1.0
uuid: ^4.2.0
dev_dependencies:
lints: ^2.0.0
lints: ^3.0.0
test: ^1.18.0
drift_dev:
drift_testcases:

View File

@ -1,6 +1,7 @@
import 'package:drift/drift.dart';
import 'package:drift_postgres/drift_postgres.dart';
import 'package:postgres/postgres.dart' as pg;
import 'package:postgres/postgres.dart';
import 'package:test/test.dart';
import 'package:uuid/uuid.dart';
@ -39,7 +40,10 @@ void main() {
}
group('uuid', () => testWith(PgTypes.uuid, Uuid().v4obj()));
group('interval', () => testWith(PgTypes.interval, Duration(seconds: 15)));
group(
'interval',
() => testWith(PgTypes.interval, Interval(months: 2, microseconds: 1234)),
);
group('json', () => testWith(PgTypes.json, {'foo': 'bar'}));
group('jsonb', () => testWith(PgTypes.jsonb, {'foo': 'bar'}));
group('point', () => testWith(PgTypes.point, pg.Point(90, -90)));