Skip to content

Commit 5ccc018

Browse files
committed
Add toptics to dartdoc documentation
1 parent 9e9937e commit 5ccc018

26 files changed

+210
-15
lines changed

sqlite3/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 2.7.3-dev
22

33
- Web: Support `localtime` datetime modifier in SQLite.
4+
- Introduce topics to dartdoc documentation.
45

56
## 2.7.2
67

sqlite3/dartdoc_options.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dartdoc:
2+
categories:
3+
"common":
4+
markdown: doc/common.md
5+
name: Cross-platform definitions
6+
"native":
7+
markdown: doc/native.md
8+
name: Native only
9+
"wasm":
10+
markdown: doc/wasm.md
11+
name: Web only

sqlite3/doc/common.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Definitions and common interfaces that are implemented by both the native
2+
and the web-specific bindings to SQLite.
3+
4+
Restricting your usage of the sqlite3 package to `package:sqlite3/common.dart`
5+
means that your code can run on all platforms.
6+
However, this doesn't give you access to the actual implementations that are part
7+
of the native and web implementations.
8+
You can write most of your database code with the common definitions and then use
9+
conditional imports to make an implementation available. For this, create three files:
10+
11+
1. `database_stub.dart`.
12+
2. `database_native.dart`.
13+
3. `datbaase_web.dart`.
14+
15+
The content of these files depends on your needs, but could look like this:
16+
17+
```dart
18+
// database_stub.dart
19+
import 'package:sqlite3/common.dart';
20+
21+
Future<CommonDatabase> openDatabase() async {
22+
throw UnsupportedError('Unknown platform');
23+
}
24+
```
25+
26+
```dart
27+
// database_native.dart
28+
import 'package:sqlite3/sqlite3.dart';
29+
30+
Future<CommonDatabase> openDatabase() async {
31+
final path = await pickDatabasePath(); // e.g. with package:path_provider
32+
return sqlite3.open(path);
33+
}
34+
```
35+
36+
```dart
37+
// database_web.dart
38+
import 'package:sqlite3/wasm.dart';
39+
40+
Future<CommonDatabase> openDatabase() async {
41+
final sqlite = await WasmSqlite3.loadFromUrl(Uri.parse('sqlite3.wasm'));
42+
final fs = await IndexedDbFileSystem.open(dbName: 'app.db');
43+
sqlite.registerVirtualFileSystem(fs, makeDefault: true);
44+
return sqlite.open('/app.db');
45+
}
46+
```
47+
48+
With those files, you can use a conditional imports to support both web and native platforms:
49+
50+
```dart
51+
import 'database_stub.dart'
52+
if (dart.library.io) 'database_native.dart'
53+
if (dart.library.js_interop) 'database_web.dart';
54+
```

sqlite3/doc/native.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Libraries related to accessing SQLite functions via `dart:ffi` on native platforms.

sqlite3/doc/wasm.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APIs for using SQLite in web contexts, accessing SQLite through a WebAssembly module.

sqlite3/lib/common.dart

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/// Exports common interfaces that are implemented by both the `dart:ffi` and
22
/// the `dart:js` WASM version of this library.
3+
///
4+
/// {@category common}
5+
/// {@canonicalFor database.CommonDatabase}
6+
/// {@canonicalFor statement.CommonPreparedStatement}
37
library;
48

59
export 'src/constants.dart';

sqlite3/lib/open.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// Utils to open a [DynamicLibrary] on platforms that aren't supported by
22
/// default.
3+
///
4+
/// {@category native}
35
library;
46

57
import 'dart:ffi';

sqlite3/lib/sqlite3.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/// Dart bindings to `sqlite3`.
2+
///
3+
/// {@category native}
24
library;
35

46
// Hide common base classes that have more specific ffi-APIs.

sqlite3/lib/src/constants.dart

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
///
1111
/// See also: SQLITE_IOERR_READ | extended result codes,
1212
/// sqlite3_vtab_on_conflictstatic const int ) SQLITE_ROLLBACK | result codes.
13+
/// {@category common}
1314
final class SqlError {
1415
/// Successful result
1516
static const int SQLITE_OK = 0;
@@ -112,6 +113,7 @@ final class SqlError {
112113
/// Note that the primary result code is always a part of the extended result code. Given a full 32-bit extended result code, the application can always find the corresponding primary result code merely by extracting the least significant 8 bits of the extended result code.
113114
///
114115
/// All extended result codes are also error codes. Hence the terms "extended result code" and "extended error code" are interchangeable.
116+
/// {@category common}
115117
final class SqlExtendedError {
116118
/// The sqlite3_load_extension() interface loads an extension into a single database connection.
117119
///
@@ -374,6 +376,7 @@ final class SqlExtendedError {
374376
/// These bit values are intended for use in the
375377
/// 3rd parameter to the [sqlite3_open_v2static const int )] interface and
376378
/// in the 4th parameter to the `xopen` method.
379+
/// {@category common}
377380
final class SqlFlag {
378381
/// Ok for sqlite3_open_v2static const int )
379382
static const int SQLITE_OPEN_READONLY = 0x00000001;
@@ -436,7 +439,9 @@ final class SqlFlag {
436439
static const int SQLITE_OPEN_WAL = 0x00080000;
437440
}
438441

439-
// Prepare flags, https://www.sqlite.org/c3ref/c_prepare_normalize.html
442+
/// Prepare flags, https://www.sqlite.org/c3ref/c_prepare_normalize.html
443+
///
444+
/// {@category common}
440445
final class SqlPrepareFlag {
441446
///The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner that the prepared statement will be retained for a long time and probably reused many times.
442447
/// Without this flag, sqlite3_prepare_v3static const int ) and sqlite3_prepare16_v3static const int ) assume that the prepared statement will be used just once or at most a few times and then destroyed using sqlite3_finalizestatic const int ) relatively soon.
@@ -453,6 +458,8 @@ final class SqlPrepareFlag {
453458
}
454459

455460
/// Datatypes, https://sqlite.org/c3ref/c_blob.html
461+
///
462+
/// {@category common}
456463
final class SqlType {
457464
static const int SQLITE_INTEGER = 1;
458465
static const int SQLITE_FLOAT = 2;
@@ -463,6 +470,8 @@ final class SqlType {
463470

464471
/// Text Encodings, https://www.sqlite.org/c3ref/c_any.html
465472
/// These constant define integer codes that represent the various text encodings supported by SQLite.
473+
///
474+
/// {@category common}
466475
final class SqlTextEncoding {
467476
///IMP: R-37514-35566
468477
static const int SQLITE_UTF8 = 1;
@@ -484,6 +493,8 @@ final class SqlTextEncoding {
484493
}
485494

486495
/// File lock levels, https://www.sqlite.org/c3ref/c_lock_exclusive.html
496+
///
497+
/// {@category common}
487498
final class SqlFileLockingLevels {
488499
static const SQLITE_LOCK_NONE = 0;
489500
static const SQLITE_LOCK_SHARED = 1;
@@ -493,6 +504,8 @@ final class SqlFileLockingLevels {
493504
}
494505

495506
/// Special destructors, https://www.sqlite.org/c3ref/c_static.html
507+
///
508+
/// {@category common}
496509
final class SqlSpecialDestructor {
497510
/// it means that the content pointer is constant and will never change, It does not need to be destroyed
498511
static const SQLITE_STATIC = 0;
@@ -503,6 +516,8 @@ final class SqlSpecialDestructor {
503516
}
504517

505518
/// Function flags, https://www.sqlite.org/c3ref/c_deterministic.html
519+
///
520+
/// {@category common}
506521
final class SqlFunctionFlag {
507522
/// The SQLITE_DETERMINISTIC flag means that the new function always gives the same output when the input parameters are the same
508523
static const SQLITE_DETERMINISTIC = 0x000000800;

sqlite3/lib/src/database.dart

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'statement.dart';
44
import 'constants.dart';
55

66
/// An opened sqlite3 database.
7+
///
8+
/// {@category common}
79
abstract class CommonDatabase {
810
/// Configuration for the database connection.
911
///
@@ -247,6 +249,8 @@ abstract class CommonDatabase {
247249

248250
/// The kind of an [SqliteUpdate] received through a [CommonDatabase.updates]
249251
/// stream.
252+
///
253+
/// {@category common}
250254
enum SqliteUpdateKind {
251255
// Note: Changing the order of these fields is a breaking change, as they're
252256
// used in the sqlite3_web protocol.
@@ -262,6 +266,8 @@ enum SqliteUpdateKind {
262266
}
263267

264268
/// A data change notification from sqlite.
269+
///
270+
/// {@category common}
265271
final class SqliteUpdate {
266272
/// The kind of write being reported.
267273
final SqliteUpdateKind kind;
@@ -295,6 +301,8 @@ final class SqliteUpdate {
295301
///
296302
/// More information: https://www.sqlite.org/c3ref/db_config.html
297303
/// Available options are documented in https://www.sqlite.org/c3ref/c_dbconfig_defensive.html
304+
///
305+
/// {@category common}
298306
abstract base class DatabaseConfig {
299307
/// Update configuration that accepts an int value.
300308
/// Would throw when the internal C call returns a non-zero value.

sqlite3/lib/src/exception.dart

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'dart:typed_data';
44
///
55
/// This is the only exception thrown by `package:sqlite3`. Additionally, errors
66
/// might be thrown on api misuse.
7+
///
8+
/// {@category common}
79
final class SqliteException implements Exception {
810
/// An error message indicating what went wrong.
911
final String message;

sqlite3/lib/src/ffi/api.dart

+10
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import 'implementation.dart';
99
Sqlite3? _sqlite3;
1010

1111
/// Provides access to `sqlite3` functions, such as opening new databases.
12+
///
13+
/// {@category native}
1214
Sqlite3 get sqlite3 {
1315
return _sqlite3 ??= FfiSqlite3(open.openSqlite());
1416
}
1517

1618
/// Provides access to `sqlite3` functions, such as opening new databases.
19+
///
20+
/// {@category native}
1721
abstract interface class Sqlite3 implements CommonSqlite3 {
1822
@override
1923
Database open(
@@ -60,6 +64,8 @@ abstract interface class Sqlite3 implements CommonSqlite3 {
6064
/// - this C file: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/test/ffi/test_extension.c
6165
/// - this Dart test loading it: https://github.com/simolus3/sqlite3.dart/blob/a9a379494c6b8d58a3c31cf04fe16e83b49130f1/sqlite3/test/ffi/sqlite3_test.dart#L35
6266
/// - Or, alternatively, this Flutter example: https://github.com/simolus3/sqlite3.dart/tree/main/sqlite3/example/custom_extension
67+
///
68+
/// {@category native}
6369
abstract interface class SqliteExtension {
6470
/// A sqlite extension having the given [extensionEntrypoint] as a function
6571
/// pointer.
@@ -95,6 +101,8 @@ abstract interface class SqliteExtension {
95101
///
96102
/// See [CommonDatabase] for the methods that are available on both the FFI and
97103
/// the WebAssembly implementation.
104+
///
105+
/// {@category native}
98106
abstract class Database extends CommonDatabase {
99107
/// The native database connection handle from sqlite.
100108
///
@@ -132,6 +140,8 @@ abstract class Database extends CommonDatabase {
132140
}
133141

134142
/// A prepared statement.
143+
///
144+
/// {@category native}
135145
abstract class PreparedStatement implements CommonPreparedStatement {
136146
/// The underlying `sqlite3_stmt` pointer.
137147
///

sqlite3/lib/src/ffi/load_library.dart

+10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import 'dart:math';
55
import 'package:meta/meta.dart';
66

77
/// Signature responsible for loading the dynamic sqlite3 library to use.
8+
///
9+
/// {@category native}
810
typedef OpenLibrary = DynamicLibrary Function();
911

12+
/// An operating system supported by `package:sqlite3` when opening SQLite
13+
/// libraries.
14+
///
15+
/// {@category native}
1016
enum OperatingSystem {
1117
android,
1218
linux,
@@ -19,6 +25,8 @@ enum OperatingSystem {
1925
/// The instance managing different approaches to load the [DynamicLibrary] for
2026
/// sqlite when needed. See the documentation for [OpenDynamicLibrary] to learn
2127
/// how the default opening behavior can be overridden.
28+
///
29+
/// {@category native}
2230
final OpenDynamicLibrary open = OpenDynamicLibrary._();
2331

2432
DynamicLibrary _defaultOpen() {
@@ -93,6 +101,8 @@ DynamicLibrary _defaultOpen() {
93101
/// The default behavior can be overridden for a specific OS by using
94102
/// [overrideFor]. To override the behavior on all platforms, use
95103
/// [overrideForAll].
104+
///
105+
/// {@category native}
96106
final class OpenDynamicLibrary {
97107
final Map<OperatingSystem, OpenLibrary> _overriddenPlatforms = {};
98108
OpenLibrary? _overriddenForAll;

sqlite3/lib/src/functions.dart

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ typedef ScalarFunction = Object? Function(List<Object?> arguments);
5151
/// }
5252
///}
5353
/// ```
54+
///
55+
/// {@category common}
5456
@immutable
5557
abstract class AggregateFunction<V> {
5658
/// Creates an initial context holding the initial value before [step] is
@@ -114,6 +116,8 @@ abstract class AggregateFunction<V> {
114116
/// Object? value(AggregateContext<int> context) => context.value;
115117
///}
116118
/// ```
119+
///
120+
/// {@category common}
117121
118122
@immutable
119123
abstract class WindowFunction<V> implements AggregateFunction<V> {
@@ -128,6 +132,8 @@ abstract class WindowFunction<V> implements AggregateFunction<V> {
128132
}
129133

130134
/// Application-defined context used to compute results in aggregate functions.
135+
///
136+
/// {@category common}
131137
final class AggregateContext<V> {
132138
/// The current value of this context.
133139
V value;
@@ -137,6 +143,8 @@ final class AggregateContext<V> {
137143
}
138144

139145
/// Describes how many arguments an application-defined sql function can take.
146+
///
147+
/// {@category common}
140148
final class AllowedArgumentCount {
141149
final int allowedArgs;
142150

sqlite3/lib/src/in_memory_vfs.dart

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import 'utils.dart';
1313
/// This file system is commonly used on the web as a buffer in front of
1414
/// asynchronous storage APIs like IndexedDb. It can also serve as an example on
1515
/// how to write custom file systems to be used with sqlite3.
16+
///
17+
/// {@category common}
1618
final class InMemoryFileSystem extends BaseVirtualFileSystem {
1719
final Map<String, Uint8Buffer?> fileData = {};
1820

sqlite3/lib/src/jsonb.dart

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import 'package:typed_data/typed_buffers.dart';
3737
/// ```
3838
///
3939
/// [JSONB]: https://sqlite.org/jsonb.html
40+
/// {@category common}
4041
const Codec<Object?, Uint8List> jsonb = _JsonbCodec();
4142

4243
final class _JsonbCodec extends Codec<Object?, Uint8List> {

sqlite3/lib/src/result_set.dart

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'package:meta/meta.dart';
77
///
88
/// Result sets are either completely materialized ([ResultSet] with all rows
99
/// being directly available), or executed row-by-row ([IteratingCursor]).
10+
///
11+
/// {@category common}
1012
sealed class Cursor {
1113
List<String> _columnNames;
1214

@@ -51,11 +53,15 @@ sealed class Cursor {
5153
/// names might change in the first call to [moveNext]. So, these getters are
5254
/// only reliable after [moveNext] was called once (regardless of its return
5355
/// value).
56+
///
57+
/// {@category common}
5458
abstract class IteratingCursor extends Cursor implements Iterator<Row> {
5559
IteratingCursor(super._columnNames, super.tableNames);
5660
}
5761

5862
/// Stores the full result of a select statement.
63+
///
64+
/// {@category common}
5965
final class ResultSet extends Cursor
6066
with
6167
ListMixin<Row>,
@@ -88,6 +94,8 @@ final class ResultSet extends Cursor
8894
/// value of a column by its name.
8995
/// The [columnAt] method may be used to obtain the value of a column by its
9096
/// index.
97+
///
98+
/// {@category common}
9199
final class Row
92100
with
93101
// ignore: prefer_mixin

0 commit comments

Comments
 (0)