durable_workflow_drift 0.2.0 copy "durable_workflow_drift: ^0.2.0" to clipboard
durable_workflow_drift: ^0.2.0 copied to clipboard

Drift ORM implementation of CheckpointStore for durable_workflow. Provides type-safe, reactive persistence with code-generated queries.

example/example.dart

/// Example: Durable workflow with Drift ORM persistence.
///
/// Demonstrates running a checkpoint/resume workflow backed by
/// Drift's type-safe query builder with an in-memory database.
///
/// Run with:
///   dart run example/drift_workflow.dart
library;

import 'package:drift/native.dart';
import 'package:durable_workflow/durable_workflow.dart';
import 'package:durable_workflow_drift/durable_workflow_drift.dart';

Future<void> main() async {
  // Create an in-memory Drift database.
  final db = DurableWorkflowDatabase(NativeDatabase.memory());
  final store = DriftCheckpointStore(db);

  final engine = DurableEngineImpl(
    store: store,
    timerPollInterval: const Duration(milliseconds: 100),
  );

  try {
    final result = await engine.run<String>(
      'order_processing',
      (ctx) async {
        await ctx.step<bool>('validate', () async {
          print('  [validate] Checking order...');
          return true;
        });

        final paymentId = await ctx.step<String>(
          'pay',
          () async {
            print('  [pay] Charging payment...');
            return 'PAY-001';
          },
          compensate: (result) async {
            print('  [pay:compensate] Refunding $result...');
          },
        );

        return 'Completed with payment: $paymentId';
      },
    );

    print('Workflow result: $result');
  } finally {
    engine.dispose();
    await store.close();
  }
}
0
likes
150
points
34
downloads

Documentation

API reference

Publisher

verified publisherbrodykim.work

Weekly Downloads

Drift ORM implementation of CheckpointStore for durable_workflow. Provides type-safe, reactive persistence with code-generated queries.

Repository (GitHub)
View/report issues

Topics

#workflow #drift #persistence #orm

License

MIT (license)

Dependencies

drift, durable_workflow, sqlite3

More

Packages that depend on durable_workflow_drift