JsonDataDirectory<T, K> class

A utility class for managing JSON data in a directory.

This class provides methods for creating, reading, updating, and deleting JSON data files in a specified directory. It also provides a method for listing all the JSON data files in the directory.

The class requires a Directory object representing the directory where the JSON data files are stored. It also requires four functions:

Example usage:

final directory = Directory('/path/to/data');
final dataDirectory = JsonDataDiretory(
  directory: directory,
  idGetterFunction: (data) => data.id,
  toJsonFunction: (data) => data.toJson(),
  fromJsonFunction: (json) => Data.fromJson(json),
);

Constructors

JsonDataDirectory({required Directory directory, required K idGetterFunction(T), required JsonMap toJsonFunction(T), required T fromJsonFunction(JsonMap), String encriptionKey = ''})

Properties

directory Directory
final
encriptionKey String
final
fromJsonFunction → T Function(JsonMap)
final
hashCode int
The hash code for this object.
no setterinherited
idGetterFunction → K Function(T)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
toJsonFunction JsonMap Function(T)
final

Methods

create(T data) Future<K>
Creates a file in the data directory with the given data.
createSync(T data) → K
Creates a file in the data directory with the given data.
delete(K id) Future<K>
Deletes the data with the specified ID.
deleteSync(K id) → K
Deletes the data with the specified ID.
list() Future<Iterable<T>>
Retrieves a list of objects of type T from the directory.
listSync() Iterable<T>
Retrieves a list of objects of type T from the directory.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(String id) Future<T?>
Reads the data with the specified ID.
readSync(K id) → T?
Reads the data with the specified ID.
toString() String
A string representation of this object.
inherited
update(T data) Future<K>
Updates the data with the specified ID.
updateSync(T data) → K
Updates the data with the specified ID.
upsert(T data) Future<K>
Create or update the data with the specified ID.
upsertSync(T data) → K

Operators

operator ==(Object other) bool
The equality operator.
inherited