Skip to content

Commit 7688d8e

Browse files
committed
return db
1 parent ae5e869 commit 7688d8e

16 files changed

+101
-264
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

3-
## [0.6.0] - 2025-07-12
3+
## [0.7.1]
4+
- Update binary
5+
6+
## [0.7.0]
7+
- Improve hot reload
8+
9+
## [0.6.0]
410

511
### 🎉 Major Features
612

@@ -147,7 +153,7 @@
147153
#### Changed
148154
- **Architecture**: Multi-backend architecture with platform-optimized storage solutions
149155
- **Documentation**: Comprehensive documentation explaining technical decisions and platform differences
150-
- **API Exports**: Added missing exports for `LocalDbModel`, `ErrorLocalDb`, and `LocalDbResult` types
156+
- **API Exports**: Added missing exports for `LocalDbModel`, `ErrorLocalDb`, and `Result` types
151157
- **Example App**: Enhanced UI showing current platform and storage backend information
152158

153159
#### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Add to your pubspec.yaml:
6161

6262
```yaml
6363
dependencies:
64-
flutter_local_db: ^0.5.1
64+
flutter_local_db: ^0.7.1
6565
```
6666
6767
## Basic Usage

lib/flutter_local_db.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,4 @@ export 'src/widgets/local_db_lifecycle_manager.dart';
1616
export 'src/model/local_db_request_model.dart';
1717

1818
/// Exports the error model
19-
export 'src/model/local_db_error_model.dart';
20-
21-
/// Exports the result type for handling operations
22-
export 'src/service/local_db_result.dart';
19+
export 'src/model/local_db_error_model.dart';

lib/src/bridge/local_db_bridge.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import 'package:flutter_local_db/src/enum/ffi_native_lib_location.dart';
1212
import 'package:flutter_local_db/src/interface/local_db_request_impl.dart';
1313
import 'package:flutter_local_db/src/model/local_db_error_model.dart';
1414
import 'package:flutter_local_db/src/model/local_db_request_model.dart';
15-
import 'package:flutter_local_db/src/service/local_db_result.dart';
15+
1616
import 'package:path_provider/path_provider.dart';
1717

1818
import 'dart:io' show Platform;
1919
import 'package:flutter/foundation.dart' show kIsWeb;
20+
import 'package:result_controller/result_controller.dart';
2021

2122
/// opaque extension
2223
final class AppDbState extends Opaque {}
@@ -36,7 +37,7 @@ class LocalDbBridge extends LocalSbRequestImpl {
3637

3738
static final LocalDbBridge instance = LocalDbBridge._();
3839

39-
LocalDbResult<DynamicLibrary, String>? _lib;
40+
Result<DynamicLibrary, String>? _lib;
4041
Pointer<AppDbState>? _dbInstance; // Cambiado de late a nullable
4142
String?
4243
_lastDatabaseName; // Almacena el último nombre de base de datos utilizado
@@ -257,7 +258,7 @@ class LocalDbBridge extends LocalSbRequestImpl {
257258
}
258259

259260
@override
260-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> post(
261+
Future<Result<LocalDbModel, ErrorLocalDb>> post(
261262
LocalDbModel model,
262263
) async {
263264
if (!(await ensureConnectionValid())) {
@@ -302,7 +303,7 @@ class LocalDbBridge extends LocalSbRequestImpl {
302303
}
303304

304305
@override
305-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> getById(String id) async {
306+
Future<Result<LocalDbModel, ErrorLocalDb>> getById(String id) async {
306307
if (!(await ensureConnectionValid())) {
307308
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
308309
}
@@ -344,7 +345,7 @@ class LocalDbBridge extends LocalSbRequestImpl {
344345
}
345346

346347
@override
347-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> put(
348+
Future<Result<LocalDbModel, ErrorLocalDb>> put(
348349
LocalDbModel model,
349350
) async {
350351
if (!(await ensureConnectionValid())) {
@@ -386,7 +387,7 @@ class LocalDbBridge extends LocalSbRequestImpl {
386387
}
387388

388389
@override
389-
Future<LocalDbResult<bool, ErrorLocalDb>> cleanDatabase() async {
390+
Future<Result<bool, ErrorLocalDb>> cleanDatabase() async {
390391
if (!(await ensureConnectionValid())) {
391392
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
392393
}
@@ -410,7 +411,7 @@ class LocalDbBridge extends LocalSbRequestImpl {
410411
}
411412

412413
@override
413-
Future<LocalDbResult<bool, ErrorLocalDb>> delete(String id) async {
414+
Future<Result<bool, ErrorLocalDb>> delete(String id) async {
414415
if (!(await ensureConnectionValid())) {
415416
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
416417
}
@@ -442,7 +443,7 @@ class LocalDbBridge extends LocalSbRequestImpl {
442443
}
443444

444445
@override
445-
Future<LocalDbResult<List<LocalDbModel>, ErrorLocalDb>> getAll() async {
446+
Future<Result<List<LocalDbModel>, ErrorLocalDb>> getAll() async {
446447
// Verificar la conexión antes de proceder
447448
if (!await ensureConnectionValid()) {
448449
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
@@ -493,7 +494,7 @@ class LocalDbBridge extends LocalSbRequestImpl {
493494
}
494495

495496
sealed class CurrentPlatform {
496-
static Future<LocalDbResult<DynamicLibrary, String>>
497+
static Future<Result<DynamicLibrary, String>>
497498
loadRustNativeLib() async {
498499
// Web platform doesn't use FFI, this should not be called on web
499500
if (kIsWeb) {

lib/src/bridge/web_local_db_bridge.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:web/web.dart' as web;
66
import 'package:flutter_local_db/src/interface/local_db_request_impl.dart';
77
import 'package:flutter_local_db/src/model/local_db_error_model.dart';
88
import 'package:flutter_local_db/src/model/local_db_request_model.dart';
9-
import 'package:flutter_local_db/src/service/local_db_result.dart';
9+
import 'package:result_controller/result_controller.dart';
1010

1111
/// Web implementation of LocalDB using native IndexedDB APIs
1212
/// This implementation provides the same interface as the FFI bridge
@@ -109,7 +109,7 @@ class WebLocalDbBridge extends LocalSbRequestImpl {
109109
}
110110

111111
@override
112-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> post(
112+
Future<Result<LocalDbModel, ErrorLocalDb>> post(
113113
LocalDbModel model,
114114
) async {
115115
if (!await ensureConnectionValid()) {
@@ -158,7 +158,7 @@ class WebLocalDbBridge extends LocalSbRequestImpl {
158158
}
159159

160160
@override
161-
Future<LocalDbResult<LocalDbModel?, ErrorLocalDb>> getById(String id) async {
161+
Future<Result<LocalDbModel?, ErrorLocalDb>> getById(String id) async {
162162
if (!await ensureConnectionValid()) {
163163
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
164164
}
@@ -197,7 +197,7 @@ class WebLocalDbBridge extends LocalSbRequestImpl {
197197
}
198198

199199
@override
200-
Future<LocalDbResult<List<LocalDbModel>, ErrorLocalDb>> getAll() async {
200+
Future<Result<List<LocalDbModel>, ErrorLocalDb>> getAll() async {
201201
if (!await ensureConnectionValid()) {
202202
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
203203
}
@@ -236,7 +236,7 @@ class WebLocalDbBridge extends LocalSbRequestImpl {
236236
}
237237

238238
@override
239-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> put(
239+
Future<Result<LocalDbModel, ErrorLocalDb>> put(
240240
LocalDbModel model,
241241
) async {
242242
if (!await ensureConnectionValid()) {
@@ -285,7 +285,7 @@ class WebLocalDbBridge extends LocalSbRequestImpl {
285285
}
286286

287287
@override
288-
Future<LocalDbResult<bool, ErrorLocalDb>> delete(String id) async {
288+
Future<Result<bool, ErrorLocalDb>> delete(String id) async {
289289
if (!await ensureConnectionValid()) {
290290
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
291291
}
@@ -322,7 +322,7 @@ class WebLocalDbBridge extends LocalSbRequestImpl {
322322
}
323323

324324
@override
325-
Future<LocalDbResult<bool, ErrorLocalDb>> cleanDatabase() async {
325+
Future<Result<bool, ErrorLocalDb>> cleanDatabase() async {
326326
if (!await ensureConnectionValid()) {
327327
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
328328
}

lib/src/database/database_interface.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter_local_db/src/model/local_db_error_model.dart';
22
import 'package:flutter_local_db/src/model/local_db_request_model.dart';
3-
import 'package:flutter_local_db/src/service/local_db_result.dart';
3+
import 'package:result_controller/result_controller.dart';
44

55
/// Abstract interface for database implementations across all platforms.
66
/// This interface ensures that both native (FFI) and web (IndexedDB)
@@ -16,35 +16,35 @@ abstract class DatabaseInterface {
1616
///
1717
/// [model] - The model containing data to store
1818
/// Returns a Result with the created model or an error
19-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> post(LocalDbModel model);
19+
Future<Result<LocalDbModel, ErrorLocalDb>> post(LocalDbModel model);
2020

2121
/// Retrieve a record by its unique identifier
2222
///
2323
/// [id] - The unique identifier of the record
2424
/// Returns a Result with the model (or null if not found) or an error
25-
Future<LocalDbResult<LocalDbModel?, ErrorLocalDb>> getById(String id);
25+
Future<Result<LocalDbModel?, ErrorLocalDb>> getById(String id);
2626

2727
/// Retrieve all records from the database
2828
///
2929
/// Returns a Result with a list of all models or an error
30-
Future<LocalDbResult<List<LocalDbModel>, ErrorLocalDb>> getAll();
30+
Future<Result<List<LocalDbModel>, ErrorLocalDb>> getAll();
3131

3232
/// Update an existing record in the database
3333
///
3434
/// [model] - The model with updated data
3535
/// Returns a Result with the updated model or an error
36-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> put(LocalDbModel model);
36+
Future<Result<LocalDbModel, ErrorLocalDb>> put(LocalDbModel model);
3737

3838
/// Delete a record by its unique identifier
3939
///
4040
/// [id] - The unique identifier of the record to delete
4141
/// Returns a Result with success status or an error
42-
Future<LocalDbResult<bool, ErrorLocalDb>> delete(String id);
42+
Future<Result<bool, ErrorLocalDb>> delete(String id);
4343

4444
/// Clear all records from the database
4545
///
4646
/// Returns a Result with success status or an error
47-
Future<LocalDbResult<bool, ErrorLocalDb>> cleanDatabase();
47+
Future<Result<bool, ErrorLocalDb>> cleanDatabase();
4848

4949
/// Close the database connection and free resources
5050
///

lib/src/database/database_mock.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'dart:convert';
44
import '../core/log.dart';
55
import '../model/local_db_error_model.dart';
66
import '../model/local_db_request_model.dart';
7-
import '../service/local_db_result.dart';
7+
import 'package:result_controller/result_controller.dart';
88
import 'database_interface.dart';
99

1010
/// Mock database implementation for testing purposes.
@@ -103,7 +103,7 @@ class DatabaseMock implements DatabaseInterface {
103103
}
104104

105105
@override
106-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> post(
106+
Future<Result<LocalDbModel, ErrorLocalDb>> post(
107107
LocalDbModel model,
108108
) async {
109109
Log.d('Mock POST operation for ID: ${model.id}');
@@ -149,7 +149,7 @@ class DatabaseMock implements DatabaseInterface {
149149
}
150150

151151
@override
152-
Future<LocalDbResult<LocalDbModel?, ErrorLocalDb>> getById(String id) async {
152+
Future<Result<LocalDbModel?, ErrorLocalDb>> getById(String id) async {
153153
Log.d('Mock GET operation for ID: $id');
154154

155155
await _simulateDelay();
@@ -182,7 +182,7 @@ class DatabaseMock implements DatabaseInterface {
182182
}
183183

184184
@override
185-
Future<LocalDbResult<List<LocalDbModel>, ErrorLocalDb>> getAll() async {
185+
Future<Result<List<LocalDbModel>, ErrorLocalDb>> getAll() async {
186186
Log.d('Mock GET ALL operation');
187187

188188
await _simulateDelay();
@@ -204,7 +204,7 @@ class DatabaseMock implements DatabaseInterface {
204204
}
205205

206206
@override
207-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> put(
207+
Future<Result<LocalDbModel, ErrorLocalDb>> put(
208208
LocalDbModel model,
209209
) async {
210210
Log.d('Mock PUT operation for ID: ${model.id}');
@@ -248,7 +248,7 @@ class DatabaseMock implements DatabaseInterface {
248248
}
249249

250250
@override
251-
Future<LocalDbResult<bool, ErrorLocalDb>> delete(String id) async {
251+
Future<Result<bool, ErrorLocalDb>> delete(String id) async {
252252
Log.d('Mock DELETE operation for ID: $id');
253253

254254
await _simulateDelay();
@@ -280,7 +280,7 @@ class DatabaseMock implements DatabaseInterface {
280280
}
281281

282282
@override
283-
Future<LocalDbResult<bool, ErrorLocalDb>> cleanDatabase() async {
283+
Future<Result<bool, ErrorLocalDb>> cleanDatabase() async {
284284
Log.d('Mock CLEAN DATABASE operation');
285285

286286
await _simulateDelay();
@@ -357,7 +357,7 @@ class DatabaseMock implements DatabaseInterface {
357357
return random < (_errorRate * 100);
358358
}
359359

360-
LocalDbResult<T, ErrorLocalDb> _createError<T>(String message) {
360+
Result<T, ErrorLocalDb> _createError<T>(String message) {
361361
Log.e('Mock database error: $message');
362362

363363
final error = ErrorLocalDb(

lib/src/database/database_native.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../enum/ffi_functions.dart';
1111
import '../enum/ffi_native_lib_location.dart';
1212
import '../model/local_db_error_model.dart';
1313
import '../model/local_db_request_model.dart';
14-
import '../service/local_db_result.dart';
14+
import 'package:result_controller/result_controller.dart';
1515
import 'database_interface.dart';
1616

1717
/// opaque extension
@@ -97,7 +97,7 @@ class DatabaseNative implements DatabaseInterface {
9797

9898
static final DatabaseNative instance = DatabaseNative._();
9999

100-
LocalDbResult<DynamicLibrary, String>? _lib;
100+
Result<DynamicLibrary, String>? _lib;
101101
Pointer<AppDbState>? _dbInstance;
102102
String? _lastDatabaseName;
103103

@@ -194,7 +194,7 @@ class DatabaseNative implements DatabaseInterface {
194194
}
195195
}
196196

197-
Future<LocalDbResult<DynamicLibrary, String>> _loadRustNativeLib() async {
197+
Future<Result<DynamicLibrary, String>> _loadRustNativeLib() async {
198198
if (Platform.isAndroid) {
199199
return Ok(DynamicLibrary.open(FFiNativeLibLocation.android.lib));
200200
}
@@ -583,7 +583,7 @@ class DatabaseNative implements DatabaseInterface {
583583
}
584584

585585
@override
586-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> post(
586+
Future<Result<LocalDbModel, ErrorLocalDb>> post(
587587
LocalDbModel model,
588588
) async {
589589
if (!await ensureConnectionValid()) {
@@ -628,7 +628,7 @@ class DatabaseNative implements DatabaseInterface {
628628
}
629629

630630
@override
631-
Future<LocalDbResult<LocalDbModel?, ErrorLocalDb>> getById(String id) async {
631+
Future<Result<LocalDbModel?, ErrorLocalDb>> getById(String id) async {
632632
if (!await ensureConnectionValid()) {
633633
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
634634
}
@@ -672,7 +672,7 @@ class DatabaseNative implements DatabaseInterface {
672672
}
673673

674674
@override
675-
Future<LocalDbResult<List<LocalDbModel>, ErrorLocalDb>> getAll() async {
675+
Future<Result<List<LocalDbModel>, ErrorLocalDb>> getAll() async {
676676
if (!await ensureConnectionValid()) {
677677
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
678678
}
@@ -722,7 +722,7 @@ class DatabaseNative implements DatabaseInterface {
722722
}
723723

724724
@override
725-
Future<LocalDbResult<LocalDbModel, ErrorLocalDb>> put(
725+
Future<Result<LocalDbModel, ErrorLocalDb>> put(
726726
LocalDbModel model,
727727
) async {
728728
if (!await ensureConnectionValid()) {
@@ -767,7 +767,7 @@ class DatabaseNative implements DatabaseInterface {
767767
}
768768

769769
@override
770-
Future<LocalDbResult<bool, ErrorLocalDb>> delete(String id) async {
770+
Future<Result<bool, ErrorLocalDb>> delete(String id) async {
771771
if (!await ensureConnectionValid()) {
772772
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
773773
}
@@ -802,7 +802,7 @@ class DatabaseNative implements DatabaseInterface {
802802
}
803803

804804
@override
805-
Future<LocalDbResult<bool, ErrorLocalDb>> cleanDatabase() async {
805+
Future<Result<bool, ErrorLocalDb>> cleanDatabase() async {
806806
if (!await ensureConnectionValid()) {
807807
return Err(ErrorLocalDb.databaseError('Database connection is invalid'));
808808
}

0 commit comments

Comments
 (0)