Skip to content

Commit

Permalink
Implemented base Drift schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
JaffaKetchup committed Jan 23, 2025
1 parent fe58113 commit 32a1770
Show file tree
Hide file tree
Showing 20 changed files with 4,883 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"yaml.schemas": {
"https://json.schemastore.org/dart-build": [
"build.yaml",
"*.build.yaml",
"build.*.yaml"
]
}
}
13 changes: 13 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
targets:
$default:
builders:
drift_dev:
enabled: false
drift_dev:analyzer:
enabled: true
options: &options
named_parameters: true
store_date_time_values_as_text: true
drift_dev:modular:
enabled: true
options: *options
1 change: 1 addition & 0 deletions example/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ android {
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
}

buildTypes {
Expand Down
90 changes: 90 additions & 0 deletions lib/src/backend/impls/drift/native/backend/backend.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright © Luka S (JaffaKetchup) under GPL-v3
// A full license can be found at .\LICENSE

import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';
import 'dart:math';

import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';

import '../../../../../../flutter_map_tile_caching.dart';
import '../../../../../misc/int_extremes.dart';
import '../../../../export_internal.dart';
import '../models/generated/objectbox.g.dart';
import '../models/src/recovery.dart';
import '../models/src/recovery_region.dart';
import '../models/src/root.dart';
import '../database/models/store.dart';
import '../models/src/tile.dart';

export 'package:objectbox/objectbox.dart' show StorageException;

part 'internal_workers/standard/cmd_type.dart';
part 'internal_workers/standard/worker.dart';
part 'internal_workers/shared.dart';
part 'internal_workers/thread_safe.dart';
part 'internal.dart';

/// Implementation of [FMTCBackend] that uses ObjectBox as the storage database
///
/// On web, this redirects to a no-op implementation that throws
/// [UnsupportedError]s when attempting to use [initialise] or [uninitialise],
/// and [RootUnavailable] when trying to use any other method.
final class FMTCObjectBoxBackend implements FMTCBackend {
/// {@macro fmtc.backend.initialise}
///
/// ---
///
/// [maxDatabaseSize] is the maximum size the database file can grow
/// to, in KB. Exceeding it throws [DbFullException] (from
/// 'package:objectbox') on write operations. Defaults to 10 GB (10000000 KB).
///
/// [macosApplicationGroup] should be set when creating a sandboxed macOS app,
/// specify the application group (of less than 20 chars). See
/// [the ObjectBox docs](https://docs.objectbox.io/getting-started) for
/// details.
///
/// [rootIsolateToken] should only be used in exceptional circumstances where
/// this backend is being initialised in a seperate isolate (or background)
/// thread.
///
/// Avoid using [useInMemoryDatabase] outside of testing purposes.
@override
Future<void> initialise({
String? rootDirectory,
int maxDatabaseSize = 10000000,
String? macosApplicationGroup,
RootIsolateToken? rootIsolateToken,
@visibleForTesting bool useInMemoryDatabase = false,
}) =>
FMTCObjectBoxBackendInternal._instance.initialise(
rootDirectory: rootDirectory,
maxDatabaseSize: maxDatabaseSize,
macosApplicationGroup: macosApplicationGroup,
useInMemoryDatabase: useInMemoryDatabase,
rootIsolateToken: rootIsolateToken,
);

/// {@macro fmtc.backend.uninitialise}
///
/// If [immediate] is `true`, any operations currently underway will be lost,
/// as the worker will be killed as quickly as possible (not necessarily
/// instantly).
/// If `false`, all operations currently underway will be allowed to complete,
/// but any operations started after this method call will be lost.
@override
Future<void> uninitialise({
bool deleteRoot = false,
bool immediate = false,
}) =>
FMTCObjectBoxBackendInternal._instance
.uninitialise(deleteRoot: deleteRoot, immediate: immediate);
}
Loading

0 comments on commit 32a1770

Please sign in to comment.