class

Change::SQL::Repo

Inherits Reference < Object

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.

Constructors

new(conn : DB::Database)
Source

Instance methods

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.

Source
conn
Source
conn=(conn : DB::Database)
Source
delete(queryable : T.class, id) forall T

Delete the record of queryable with the primary key that matches the given id value.

Source
get(queryable : T.class, id) : T | Nil forall T

Get the record of queryable whose primary key matches the given id value. If no record matches the query, nil is returned instead.

Source
insert(changeset : Changeset(T, U)) : Changeset(T, U) forall T, U

Attempt to save a record of T to the repository. The insertion is only attempted if the changeset is currently valid.

Source
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.

If multiple records are returned by the query, the first is selected. If no record matches, returns nil.

Source
update(changeset : Changeset(T, U)) : Changeset(T, U) forall T, U

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.

Source