Skip to content

Commit 6d0b158

Browse files
committed
Rename dispose to close
1 parent 5a7bb65 commit 6d0b158

File tree

30 files changed

+174
-140
lines changed

30 files changed

+174
-140
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ jobs:
3333
# because caches from non-default branches aren't visible to runs on tags.
3434
# On windows, the sqlite3 build is not reproducible. So to avoid a hash mismatch, we temporarily use artifacts
3535
# built for a test run for releases as well.
36-
artifact-ids: "4427181234"
36+
artifact-ids: "4438896082"
3737
repository: simolus3/sqlite3.dart
38-
run-id: "18966728824"
38+
run-id: "19001906517"
3939
github-token: ${{ github.token }}
4040
path: sqlite-compiled
4141
- name: Set tag name

examples/flutter_integration_tests/integration_test/integration_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ void main() {
110110
}
111111

112112
extension on Database {
113-
void closeWhenDone() => addTearDown(dispose);
113+
void closeWhenDone() => addTearDown(close);
114114
}

examples/flutter_integration_tests/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class _SqliteDiagnosticTextState extends State<_SqliteDiagnosticText> {
3535
setState(() {
3636
_text = 'Version: ${sqlite3.version}\nOptions: $options';
3737
});
38-
db.dispose();
38+
db.close();
3939
}
4040

4141
@override

sqlite3/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 3.0.0-beta.1
1+
## 3.0.0-beta.2
22

33
- __Breaking change__: Use [build hooks](https://dart.dev/tools/hooks) to load
44
SQLite instead of `DynamicLibrary`.
@@ -9,7 +9,10 @@
99
package is now part of `package:sqlite3`.
1010
- __Breaking change__: Parameters to `SqliteException`s are now named.
1111
- On native platforms, use native finalizers to reliably clear statements and databases.
12+
- On the web, use regular finalizers more consistently.
1213
- Refactor binding text and blob values to reduce the chance of memory leaks.
14+
- Deprecated `dispose()` on `CommonDatabase` and `CommonPreparedStatement`. Use `close()`
15+
instead.
1316

1417
## 2.9.4
1518

sqlite3/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ For native platforms, the basic sketch for using this library is to:
1919
open a temporary in-memory database.
2020
3. Use `Database.execute` or `Database.prepare` to execute statements directly
2121
or by preparing them first.
22-
4. Don't forget to close prepared statements or the database with `dispose()`
23-
once you no longer need them.
22+
4. Consider closing statements or databases explicitly with `close()` once you're
23+
done with them. `package:sqlite3` uses native finalizers to do that automatically
24+
too, though.
2425

2526
For a more complete example on how to use this library, see the [example](https://pub.dev/packages/sqlite3/example).
2627

sqlite3/example/custom_extension/test/extension_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void main() {
99

1010
test('can use vec0', () {
1111
final db = sqlite3.openInMemory();
12-
addTearDown(db.dispose);
12+
addTearDown(db.close);
1313

1414
db.execute(
1515
'create virtual table vec_examples using vec0(sample_embedding float[8])',

sqlite3/example/main.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void main() {
2626
..execute(['Nirvana']);
2727

2828
// Dispose a statement when you don't need it anymore to clean up resources.
29-
stmt.dispose();
29+
stmt.close();
3030

3131
// You can run select statements with PreparedStatement.select, or directly
3232
// on the database:
@@ -49,6 +49,7 @@ void main() {
4949
);
5050
print(db.select('SELECT dart_version()'));
5151

52-
// Don't forget to dispose the database to avoid memory leaks
53-
db.dispose();
52+
// Don't forget to dispose the database to avoid memory leaks (optional on
53+
// native platforms).
54+
db.close();
5455
}

sqlite3/example/web/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Future<void> main() async {
2626
..execute('pragma user_version = 1')
2727
..execute('CREATE TABLE foo (bar INTEGER NOT NULL);')
2828
..execute('INSERT INTO foo (bar) VALUES (?)', [3])
29-
..dispose();
29+
..close();
3030

3131
final db = sqlite3.open('/database');
3232
print(db.select('SELECT * FROM foo'));
@@ -50,7 +50,7 @@ Future<void> main() async {
5050
..execute('pragma user_version = 1')
5151
..execute('CREATE TABLE foo (bar INTEGER NOT NULL);')
5252
..execute('INSERT INTO foo (bar) VALUES (?)', [3])
53-
..dispose();
53+
..close();
5454

5555
final db = sqlite3.open('/database');
5656
try {

sqlite3/example/web/worker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void main() {
3939
..execute('pragma user_version = 1')
4040
..execute('CREATE TABLE foo (bar INTEGER NOT NULL);')
4141
..execute('INSERT INTO foo (bar) VALUES (?)', [3])
42-
..dispose();
42+
..close();
4343

4444
final db = sqlite3.open('/database');
4545
print(db.select('SELECT * FROM foo'));

sqlite3/lib/src/database.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ abstract class CommonDatabase {
140140
/// The [persistent] flag can be used as a hint to the query planner that the
141141
/// statement will be retained for a long time and probably reused many times.
142142
/// Without this flag, sqlite assumes that the prepared statement will be used
143-
/// just once or at most a few times before [CommonPreparedStatement.dispose]
143+
/// just once or at most a few times before [CommonPreparedStatement.close]
144144
/// is called.
145145
/// If [vtab] is disabled (it defaults to `true`) and the statement references
146146
/// a virtual table, [prepare] throws an exception.
@@ -271,7 +271,15 @@ abstract class CommonDatabase {
271271
bool get autocommit;
272272

273273
/// Closes this database and releases associated resources.
274+
@Deprecated('Call close() instead')
274275
void dispose();
276+
277+
/// Closes this database and releases associated resources.
278+
///
279+
/// On native platforms, a native finalizer will also close the connection
280+
/// automatically. On the web, finalizers are less reliable. For this reason,
281+
/// closing databases explicitly is still recommended.
282+
void close();
275283
}
276284

277285
/// The kind of an [SqliteUpdate] received through a [CommonDatabase.updates]

0 commit comments

Comments
 (0)