View Source Qh.Repo (qh v0.2.0)
Link to this section Summary
Functions
Update fields in a struct
Delete a struct in the database
Save a struct to the database
Save a struct to the database
Performs a database update for a struct and params
Save a struct to the database
Link to this section Functions
Update fields in a struct
Examples:
user = %MyApp.User{name: nil, age: nil}
user = Qh.assign(user, name: "Bob", age: 21)
# or initialize a new record
user = Qh.assign(:user, name: "Alice", age: 22)
Delete a struct in the database
Will raise if the record doesn't exists
Examples:
user = %MyApp.User{id: 2, name: "Bob", age: 21}
Qh.delete!(user)
Save a struct to the database
Inserts a new record if no primary key is set or no record exists with the current primary key.
Performs a get and an update if the record already exists.
Returns {:ok, struct}
on success or {:error, validation_errors}
on failure.
Examples:
user = %MyApp.User{id: nil, name: "Bob", age: 21}
{:ok, user} = Qh.save(user)
Save a struct to the database
Similar to save/1
but will raise on failures and return only the
struct on success.
Examples:
user = %MyApp.User{id: nil, name: "Bob", age: 21}
user = Qh.save!(user)
Performs a database update for a struct and params
Returns {:ok, struct}
on success or {:error, validation_errors}
on failure.
Examples:
user = %MyApp.User{id: 2, name: "Bob", age: 21}
{:ok, user} = Qh.update(user, age: 22)
Save a struct to the database
Similar to update/1
but will raise on failures and return only the
struct on success.
Examples:
user = %MyApp.User{id: 2, name: "Bob", age: 21}
user = Qh.update!(user, age: 22)