Skip to content

Commit 4de46af

Browse files
committed
Prepare release
1 parent e8df2c8 commit 4de46af

File tree

7 files changed

+115
-5
lines changed

7 files changed

+115
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ It can be used both in Flutter apps or in standalone Dart applications.
99
The `sqlite3_flutter_libs` and `sqlcipher_flutter_libs` packages contain no Dart code at all. Flutter users can depend
1010
on one of them to include native libraries in their apps.
1111

12+
An experimental alternative to `sqlite3_flutter_libs` based on [native assets](https://dart.dev/interop/c-interop#native-assets)
13+
is available with the `sqlite3_native_assets` package.
14+
1215
`package:sqlite3_test` contains utilities that make integrating SQLite databases into Dart tests easier.
1316
In particular, they patch `CURRENT_TIMESTAMP` and related constructs to return the (potentially faked) time
1417
returned by `package:clock`.

sqlite3/lib/sqlite3_native_library.dart

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'dart:ffi';
2+
3+
import 'package:meta/meta.dart';
4+
5+
import 'ffi/api.dart';
6+
import 'ffi/implementation.dart';
7+
8+
/// A version of [sqlite3] that uses FFI bindings backed by [native assets]
9+
/// instead of opening a [DynamicLibrary].
10+
///
11+
/// When used together with the `sqlite3_native_assets` package, using these
12+
/// bindings guarantees that a version of the SQLite library is included with
13+
/// your app. This means that `sqlite3_flutter_libs` is no longer required.
14+
/// Also, this build works on all Dart platforms and does not require Flutter.
15+
///
16+
/// Using these bindings is experimental (since native assets in Dart are an
17+
/// experimental feature).
18+
///
19+
/// [native assets](https://dart.dev/interop/c-interop#native-assets)
20+
@experimental
21+
final Sqlite3 sqlite3Native = FfiSqlite3.nativeAssets();

sqlite3_native_assets/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Simon Binder
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

sqlite3_native_assets/hook/build.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:convert';
12
import 'dart:io';
23

34
import 'package:archive/archive.dart';
@@ -27,6 +28,7 @@ void main(List<String> args) async {
2728
name: 'sqlite3',
2829
assetName: 'sqlite3_native_assets.dart',
2930
sources: [source.toFilePath()],
31+
defines: collectDefines(),
3032
);
3133

3234
await builder.run(
@@ -55,3 +57,42 @@ final class _IgnoreSourceDependency extends BuildOutputBuilder {
5557
super.addDependencies(uris.where((e) => url.extension(e.path) != '.c'));
5658
}
5759
}
60+
61+
// Note: Keep in sync with https://github.com/simolus3/sqlite-native-libraries/blob/master/sqlite3-native-library/cpp/CMakeLists.txt
62+
const _defines = '''
63+
SQLITE_ENABLE_DBSTAT_VTAB
64+
SQLITE_ENABLE_FTS5
65+
SQLITE_ENABLE_RTREE
66+
SQLITE_DQS=0
67+
SQLITE_DEFAULT_MEMSTATUS=0
68+
SQLITE_TEMP_STORE=2
69+
SQLITE_MAX_EXPR_DEPTH=0
70+
SQLITE_STRICT_SUBTYPE=1
71+
SQLITE_OMIT_AUTHORIZATION
72+
SQLITE_OMIT_DECLTYPE
73+
SQLITE_OMIT_DEPRECATED
74+
SQLITE_OMIT_PROGRESS_CALLBACK
75+
SQLITE_OMIT_SHARED_CACHE
76+
SQLITE_OMIT_TCL_VARIABLE
77+
SQLITE_OMIT_TRACE
78+
SQLITE_USE_ALLOCA
79+
SQLITE_UNTESTABLE
80+
SQLITE_HAVE_ISNAN
81+
SQLITE_HAVE_LOCALTIME_R
82+
SQLITE_HAVE_LOCALTIME_S
83+
SQLITE_HAVE_MALLOC_USABLE_SIZE
84+
SQLITE_HAVE_STRCHRNUL
85+
''';
86+
87+
Map<String, String?> collectDefines() {
88+
final entries = <String, String?>{};
89+
for (final line in const LineSplitter().convert(_defines)) {
90+
if (line.contains('=')) {
91+
final [key, value] = line.trim().split('=');
92+
entries[key] = value;
93+
} else {
94+
entries[line.trim()] = null;
95+
}
96+
}
97+
return entries;
98+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export 'package:sqlite3/sqlite3_native_library.dart';
1+
export 'package:sqlite3/src/sqlite3_native_library.dart';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:sqlite3/sqlite3.dart';
2+
import 'package:sqlite3_native_assets/sqlite3_native_assets.dart';
3+
import 'package:test/test.dart';
4+
5+
void main() {
6+
final sqlite3 = sqlite3Native;
7+
late Database database;
8+
9+
setUp(() => database = sqlite3.openInMemory());
10+
tearDown(() => database.dispose());
11+
12+
group('compiled sqlite3', () {
13+
test('enables fts5', () {
14+
database.execute('CREATE VIRTUAL TABLE foo USING fts5(a, b, c);');
15+
});
16+
17+
test('enables rtree', () {
18+
database.execute('CREATE VIRTUAL TABLE foo USING rtree(a, b, c);');
19+
});
20+
21+
test('disables double-quoted string literals by default', () {
22+
expect(
23+
() => database.execute('SELECT "not a string";'),
24+
throwsA(isA<SqliteException>()),
25+
);
26+
});
27+
});
28+
}

0 commit comments

Comments
 (0)