Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration for drift #261

Open
dickermoshe opened this issue Sep 11, 2024 · 3 comments
Open

Integration for drift #261

dickermoshe opened this issue Sep 11, 2024 · 3 comments
Labels
addons Related to addons/bridge packages like dio_logger and bloc_logger enhancement New feature or request open-to-contribution You can open Pull-request to resolve this issue

Comments

@dickermoshe
Copy link

Is your feature request related to a problem? Please describe.
There is no package for drift Link

Describe the solution you'd like
A package for drift

Describe alternatives you've considered
This implementation they have an example of

@DriftDatabase(tables: [])
class AppDatabase extends _$AppDatabase {
  AppDatabase()
      : super(drift.driftDatabase(name: "shas.db")
            .interceptWith(LogInterceptor()));

  @override
  int get schemaVersion => 1;
}

class LogInterceptor extends QueryInterceptor {
  Future<T> _run<T>(
      String description, FutureOr<T> Function() operation) async {
    final stopwatch = Stopwatch()..start();
    talker.log('Running $description');

    try {
      final result = await operation();
      talker.log(' => succeeded after ${stopwatch.elapsedMilliseconds}ms');
      return result;
    } on Object catch (e, s) {
      talker.error(' => failed after ${stopwatch.elapsedMilliseconds}ms', e, s);
      rethrow;
    }
  }

  @override
  TransactionExecutor beginTransaction(QueryExecutor parent) {
    talker.log('begin');
    return super.beginTransaction(parent);
  }

  @override
  Future<void> commitTransaction(TransactionExecutor inner) {
    return _run('commit', () => inner.send());
  }

  @override
  Future<void> rollbackTransaction(TransactionExecutor inner) {
    return _run('rollback', () => inner.rollback());
  }

  @override
  Future<void> runBatched(
      QueryExecutor executor, BatchedStatements statements) {
    return _run(
        'batch with $statements', () => executor.runBatched(statements));
  }

  @override
  Future<int> runInsert(
      QueryExecutor executor, String statement, List<Object?> args) {
    return _run(
        '$statement with $args', () => executor.runInsert(statement, args));
  }

  @override
  Future<int> runUpdate(
      QueryExecutor executor, String statement, List<Object?> args) {
    return _run(
        '$statement with $args', () => executor.runUpdate(statement, args));
  }

  @override
  Future<int> runDelete(
      QueryExecutor executor, String statement, List<Object?> args) {
    return _run(
        '$statement with $args', () => executor.runDelete(statement, args));
  }

  @override
  Future<void> runCustom(
      QueryExecutor executor, String statement, List<Object?> args) {
    return _run(
        '$statement with $args', () => executor.runCustom(statement, args));
  }

  @override
  Future<List<Map<String, Object?>>> runSelect(
      QueryExecutor executor, String statement, List<Object?> args) {
    return _run(
        '$statement with $args', () => executor.runSelect(statement, args));
  }
}

Additional context
N/A

@Frezyx Frezyx added enhancement New feature or request addons Related to addons/bridge packages like dio_logger and bloc_logger labels Oct 9, 2024
@Frezyx
Copy link
Owner

Frezyx commented Oct 9, 2024

Hello @dickermoshe !
Drift is a really popular library and we would like to have addon package to collect transactions logs.
Can you create pull-request with this new package ?

@dickermoshe
Copy link
Author

I'll add this to our todo list.

@Frezyx Frezyx added the open-to-contribution You can open Pull-request to resolve this issue label Nov 10, 2024
@Frezyx
Copy link
Owner

Frezyx commented Nov 20, 2024

Hello @dickermoshe! Any updates ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Related to addons/bridge packages like dio_logger and bloc_logger enhancement New feature or request open-to-contribution You can open Pull-request to resolve this issue
Projects
None yet
Development

No branches or pull requests

2 participants