class Change::SQL::Repo
- Change::SQL::Repo
- Reference
- Object
Overview
Generic interface for querying a repository.
For now this is implemented directly with Postgres as a backing adapter, but extracting an adapter system should be fairly simple.
Defined in:
change/sql/repo.crConstructors
Instance Method Summary
-
#all(queryable : T.class, query : Query = Query.new) : Array(T) forall T
Return all existing records of
queryable
that match the provided query, or just all records if no query is given. - #conn : DB::Database
- #conn=(conn : DB::Database)
-
#delete(queryable : T.class, id) forall T
Delete the record of
queryable
with the primary key that matches the given id value. -
#get(queryable : T.class, id) : T | Nil forall T
Get the record of
queryable
whose primary key matches the given id value. -
#insert(changeset : Changeset(T, U)) : Changeset(T, U) forall T, U
Attempt to save a record of
T
to the repository. -
#one(queryable : T.class, query : Query = Query.new) : T | Nil forall T
Return a single record of
queryable
that matches the provided query, or the first result of the query if no query is given. -
#update(changeset : Changeset(T, U)) : Changeset(T, U) forall T, U
Attempt to update a record of
T
in the repository.
Constructor Detail
Instance Method Detail
Return all existing records of queryable
that match the provided
query, or just all records if no query is given.
Delete the record of queryable
with the primary key that matches
the given id value.
Get the record of queryable
whose primary key matches the given id
value. If no record matches the query, nil
is returned instead.
Attempt to save a record of T
to the repository. The insertion is
only attempted if the changeset is currently valid.
Return a single record of queryable
that matches the provided query,
or the first result of the query if no query is given.
If multiple records are returned by the query, the first is selected. If no record matches, returns nil.
Attempt to update a record of T
in the repository. The update is only
attempted if the changeset is currently valid, and the instance of the
changeset has a primary key value set.