work_db library

WorkDB - A cross-platform local database for Dart.

This library provides implementations of the WorkDB interfaces for multiple platforms: Desktop (IO), Web, and Mobile.

Getting Started

import 'package:work_db/work_db.dart';

void main() async {
  // Simple usage with WorkDb factory
  final db = WorkDb.memory();

  // Create an item
  await db.create(ItemWithId(
    id: 'user-1',
    collection: 'users',
    item: {'name': 'John'},
  ));

  // Retrieve it
  final user = await db.retrieve(ItemId(
    id: 'user-1',
    collection: 'users',
  ));
  print(user?.item['name']); // John
}

Classes

ClientWorkDb
The main client implementation of IWorkDb.
ClientWorkDbLock
Client implementation of IWorkDb with file-based locking.
ClientWorkDbLockSync
Client implementation of IWorkDb and IWorkDbSync with file-based locking on both async and sync operations.
ILockManager
Interface for document lock management.
ILockManagerSync
Synchronous interface for document lock management.
IoWorkDb
File system implementation for Desktop/Server platforms.
IoWorkDbFactoryInput
Input configuration for creating an IoWorkDb instance.
IPathValidator
Interface for validating paths and names in WorkDB.
Item
Represents an item to be stored in the database.
ItemId
Identifies a unique item within a collection.
ItemOutput
Represents an item retrieved from the database with metadata.
ItemWithId
A combination of ItemId and Item for create/update operations.
IWebStorage
Storage interface for web platform abstraction.
IWorkDb
Interface for WorkDB database operations.
IWorkDbFactory
Interface for WorkDB factory implementations.
IWorkDbSync
Interface for WorkDB database operations. But sync!
IWorkFileSystem
Interface for low-level file system operations.
IWorkFileSystemSync
Synchronous interface for low-level file system operations.
LockInfo
LockManager
File-based implementation of ILockManager.
LockManagerSync
Synchronous file-based implementation of ILockManagerSync.
MapWebStorage
Default implementation using a Map for storage.
MemoryWorkDb
In-memory file system implementation.
MemoryWorkDbFactoryInput
Input configuration for creating a MemoryWorkDb instance.
PathValidator
Default implementation of IPathValidator.
WebWorkDb
File system implementation for Web platform using localStorage.
WebWorkDbFactoryInput
Input configuration for creating a WebWorkDb instance.
WorkDb
Convenience class with static factory methods for creating ClientWorkDb.
WorkDbConfig
Configuration options for creating a WorkDB instance.
WorkDbFactory
Factory for creating WorkDB instances.
WorkDbFactoryInput
Base class for factory input types.

Enums

PlatformType
Supported platform types for WorkDB.

Functions

createWorkDb(WorkDbConfig config) → ClientWorkDb
Creates a WorkDB instance using configuration.

Typedefs

JsonObject = Map<String, JsonValue?>
A JSON object represented as a Map with String keys.
JsonValue = Object?
A JSON-compatible value type.

Exceptions / Errors

DocumentLockedException
Exception thrown when trying to access a locked document.
FileOperationException
Exception thrown when a file operation fails.
InvalidCollectionNameException
Exception thrown when a collection name is invalid.
InvalidItemIdException
Exception thrown when an item ID is invalid.
InvalidPathException
Exception thrown when a path is invalid.
ItemAlreadyExistsException
Exception thrown when trying to create an item that already exists.
ItemNotFoundException
Exception thrown when trying to access an item that does not exist.
LockAcquisitionException
Exception thrown when a lock cannot be acquired because it's already held.