SnailRepository<T, ID> class abstract

A base class for repositories that handle the operations on database tables.

It provides methods similar to Spring Data JPA, such as saving, finding, counting, and deleting entities in the database.

Constructors

SnailRepository({required String tableName, required String primaryKeyColumn, required Map<String, Type> defineFields})
Creates an instance of SnailRepository with the specified table name, primary key column, and field definitions.

Properties

defineFields Map<String, Type>
final
hashCode int
The hash code for this object.
no setterinherited
primaryKeyColumn String
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tableName String
final

Methods

count() Future<int>
Returns the count of entities in the database.
delete(T entity) Future<int>
Deletes an entity from the database.
deleteAll(List<T>? entities) Future<int>
Deletes multiple entities from the database.
deleteById(ID id) Future<int>
Deletes an entity by its ID.
dynamicMethod(String methodName, [List? args]) Future<List<T>>
Parses the method name and constructs a query fragment.
entityToMapValue(T entity) Map<String, dynamic>
Converts an entity of type T to a map with values ready for database storage.
existsById(ID id) Future<bool>
Checks if an entity exists by its ID.
findAll({int? size, String? sort, int? page}) Future<List<T>>
Finds all entities in the database.
findAllById(List<ID> ids, {int? size, String? sort, int? page}) Future<List<T>>
Finds all entities by their IDs.
findById(ID id) Future<T?>
Finds an entity by its ID.
fromMap(Map<String, dynamic> map) → T
Converts a map to an entity of type T.
generateCreateTableQuery() String
Generates the SQL query to create the table for this repository.
getEntityId(T entity) → ID
Gets the primary key value of an entity.
keysToCamelCase(Map<String, dynamic> map) Map<String, dynamic>
Converts the keys of a given Map from snake_case to camelCase.
keysToSnakeCase(Map<String, dynamic> map) Map<String, dynamic>
Converts the keys of a given Map from camelCase to snake_case.
mapValueToEntity(Map<String, dynamic> map) → T
Converts a map from the database to an entity of type T.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save(T entity) Future<int>
Saves or updates an entity in the database.
saveAll(List<T> entities) Future<List<int>>
Saves or updates a list of entities in the database.
toCamelCase(String input) String
Converts a string from snake_case to camelCase.
toMap(T entity) Map<String, dynamic>
Converts an entity of type T to a map representation.
toSnakeCase(String input) String
Converts a string from camelCase to snake_case.
toString() String
A string representation of this object.
inherited

Operators

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