class

Avram::Database

Inherits Reference < Object

Class methods

close_connections!

Close all available connections as well as the DB

Source
connections
Source
credentials
Source
database_info
Source
delete

Run a SQL DELETE on all tables in the database

Source
exec(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#exec but with instrumentation

Source
listen(*channels : String, &block : PQ::Notification -> ) : Nil

Listens for pg_notify() calls on each channel in channels Yields a PQ::Notification object with channel, payload, and pid.

# pg_notify("callback", "123")
AppDatabase.listen("callback", "jobs") do |notification|
  notification.channel # => "callback"
  notification.payload # => "123"
end
Source
lock_id
Source
lock_id=(lock_id : UInt64 | Nil)
Source
query(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#query but with instrumentation

Source
query(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:query but with instrumentation

Source
query_all(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#query_all but with instrumentation

Source
query_all(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:query_all but with instrumentation

Source
query_each(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:query_each but with instrumentation

Source
query_one(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#query_one but with instrumentation

Source
query_one(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:query_one but with instrumentation

Source
query_one?(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#query_one? but with instrumentation

Source
query_one?(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:"query_one?" but with instrumentation

Source
rollback

Rollback the current transaction

Source
scalar(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#scalar but with instrumentation

Source
setup_connection
Source
transaction

Wrap the block in a database transaction

AppDatabase.transaction do
  # Create, read, update
  # Force a rollback with AppDatabase.rollback
end
Source
truncate

Run a SQL TRUNCATE on all tables in the database

Source
vacuum(model : Avram::Model.class | Nil = nil) : Nil

Runs a SQL VACUUM command. Optionally specify a model to run the vacuum against that table.

AppDatabase.vacuum
AppDatabase.vacuum(User)
Source
verify_connection
Source
with_lock_on(model : Avram::Model.class, mode : Avram::TableLockMode, &)

Creates a lock on the table in mode

AppDatabase.with_lock_on(User, mode: :row_exclusive) do
  user = UserQuery.new.id(1).for_update.first
  SaveUser.update!(user, name: "New Name")
end
Source

Instance methods

exec(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#exec but with instrumentation

Source
publish_query_event(query, args_, args, queryable, &)
Source
query(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#query but with instrumentation

Source
query(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:query but with instrumentation

Source
query_all(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#query_all but with instrumentation

Source
query_all(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:query_all but with instrumentation

Source
query_each(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:query_each but with instrumentation

Source
query_one(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#query_one but with instrumentation

Source
query_one(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:query_one but with instrumentation

Source
query_one?(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#query_one? but with instrumentation

Source
query_one?(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args, &)

Same as crystal-db's DB::QueryMethods#:"query_one?" but with instrumentation

Source
scalar(query, *args_, args : Array | Nil = nil, queryable : String | Nil = nil, **named_args)

Same as crystal-db's DB::QueryMethods#scalar but with instrumentation

Source

Nested types