popcorn :: Repository :: defaultinit
# A Repository is an object that can store serialized instances.
#
# Repository is the base class of all kind of persistance processes. It offers
# the base CRUD services to save (add/update), find and delete instances.
#
# Instances are stored in their serialized form. See the `serialization` package
# for more documentation.
interface Repository[E: Serializable]
# Kind of queries accepted
#
# Can be redefined to accept more precise queries depending on the backend used.
type QUERY: RepositoryQuery
# Find an instance by it's `id`
#
# `id` is an abstract thing at this stage
# TODO maybe introduce the `PrimaryKey` concept?
fun find_by_id(id: String): nullable E is abstract
# Find an instance based on `query`
fun find(query: QUERY): nullable E is abstract
# Find all instances based on `query`
#
# Using `query` == null will retrieve all the document in the repository.
fun find_all(query: nullable QUERY, skip, limit: nullable Int): Array[E] is abstract
# Count instances that matches `query`
fun count(query: nullable QUERY): Int is abstract
# Save an `instance`
fun save(instance: E): Bool is abstract
# Remove the instance with `id`
fun remove_by_id(id: String): Bool is abstract
# Remove the instance based on `query`
fun remove(query: nullable QUERY): Bool is abstract
# Remove all the instances matching on `query`
fun remove_all(query: nullable QUERY): Bool is abstract
# Remove all instances
fun clear: Bool is abstract
# Serialize an `instance` to a String.
fun serialize(instance: nullable E): nullable String is abstract
# Deserialize a `string` to an instance.
fun deserialize(string: nullable String): nullable E is abstract
end
lib/popcorn/pop_repos.nit:158,1--209,3