Skip to content

Commit

Permalink
Update to postgres 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Nov 15, 2023
1 parent 1daf212 commit e19de7c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 3 additions & 1 deletion extras/drift_postgres/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 0 additions & 5 deletions extras/drift_postgres/README.md
Original file line number Diff line number Diff line change
@@ -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/).
Expand Down
2 changes: 1 addition & 1 deletion extras/drift_postgres/lib/drift_postgres.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions extras/drift_postgres/lib/src/types.dart
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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";
}
}

Expand Down
8 changes: 4 additions & 4 deletions extras/drift_postgres/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion extras/drift_postgres/test/types_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit e19de7c

Please sign in to comment.