-
Notifications
You must be signed in to change notification settings - Fork 351
/
geopoly.dart
79 lines (64 loc) · 2.42 KB
/
geopoly.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/// https://www.sqlite.org/geopoly.html
/// The Geopoly Interface To The SQLite R*Tree Module
library geopoly;
import 'dart:typed_data';
import '../src/runtime/query_builder/query_builder.dart';
import '../src/runtime/types/mapping.dart';
/// The type used for the `_shape` column in virtual `GEOPOLY` tables.
///
/// This type is responsible for representing shape values in Dart. It is
/// created by drift when the `geopoly` extension is enabled and a `CREATE
/// VIRTUAL TABLE USING geopoly` table is declared in a `.drift` file.
final class GeopolyPolygonType implements CustomSqlType<GeopolyPolygon> {
/// Default constant constructor for the geopoly type.
const GeopolyPolygonType();
@override
String mapToSqlLiteral(GeopolyPolygon dartValue) {
throw UnimplementedError();
}
@override
Object mapToSqlParameter(GeopolyPolygon dartValue) {
switch (dartValue) {
case GeopolyPolygonString(:final value):
return value;
case GeopolyPolygonBlob(:final value):
return value;
}
}
@override
GeopolyPolygon read(Object fromSql) {
return switch (fromSql) {
Uint8List() => GeopolyPolygon.blob(fromSql),
String() => GeopolyPolygon.text(fromSql),
_ => throw UnimplementedError(),
};
}
@override
String sqlTypeName(GenerationContext context) {
throw UnimplementedError();
}
}
/// In Geopoly, a polygon can be text or a blob.
sealed class GeopolyPolygon {
const GeopolyPolygon._();
/// Creates a geopoly shape from a textual representation listing its points.
///
/// For details on the syntax for [value], see https://www.sqlite.org/geopoly.html.
const factory GeopolyPolygon.text(String value) = GeopolyPolygonString;
/// Creates a geopoly shape from the binary representation used by sqlite3.
const factory GeopolyPolygon.blob(Uint8List value) = GeopolyPolygonBlob;
}
/// A [GeopolyPolygon] being described as text.
final class GeopolyPolygonString extends GeopolyPolygon {
/// The textual description of the polygon.
final String value;
/// Creates a polygon from the underlying textual [value].
const GeopolyPolygonString(this.value) : super._();
}
/// A [GeopolyPolygon] being described as binary data.
final class GeopolyPolygonBlob extends GeopolyPolygon {
/// The binary description of the polygon.
final Uint8List value;
/// Creates a polygon from the underlying binary [value].
const GeopolyPolygonBlob(this.value) : super._();
}