Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Created July 28, 2025 04:55
Show Gist options
  • Save rodydavis/a797fff0b7300bc4a8d1214d46718f51 to your computer and use it in GitHub Desktop.
Save rodydavis/a797fff0b7300bc4a8d1214d46718f51 to your computer and use it in GitHub Desktop.
import 'dart:typed_data';
import 'package:sqlite3/sqlite3.dart';
// ignore: invalid_use_of_internal_member
import 'package:sqlite3/src/implementation/bindings.dart';
import 'package:sqlite3/src/ffi/memory.dart';
import 'dart:ffi' as ffi;
@ffi.Native<
ffi.Int Function(
ffi.Int,
ffi.Pointer<ffi.Void>,
ffi.Int,
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Int>,
ffi.Pointer<ffi.Pointer<ffi.Void>>)>()
external int sqlite3changeset_concat(
int nA,
ffi.Pointer<ffi.Void> pA,
int nB,
ffi.Pointer<ffi.Void> pB,
ffi.Pointer<ffi.Int> pnOut,
ffi.Pointer<ffi.Pointer<ffi.Void>> ppOut,
);
SqliteResult<Uint8List> changesetMerge(Uint8List a, Uint8List b) {
final aPtr = allocateBytes(a).cast<ffi.Void>();
final bPtr = allocateBytes(b).cast<ffi.Void>();
final outSize = allocate<ffi.Int>();
final outChangeset = allocate<ffi.Pointer<ffi.Void>>();
final result = sqlite3changeset_concat(
a.length,
aPtr,
b.length,
bPtr,
outSize,
outChangeset,
);
aPtr.free();
bPtr.free();
if (result != SqlError.SQLITE_OK) {
outSize.free();
outChangeset.free();
throw SqliteException(result, 'Could not concat changesets');
}
final size = outSize.value;
final changeset = outChangeset.value.cast<ffi.Uint8>().asTypedList(size);
outSize.free();
outChangeset.free();
return SqliteResult(result, changeset);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment