module Memo::Database

Overview

Database initialization and schema management

Extended Modules

Defined in:

memo/database.cr

Instance Method Summary

Instance Method Detail

def create(path : String) : DB::Database #

Create database connection and initialize schema (standalone mode)

Accepts either a file path (SQLite) or connection string (postgres://...). Sets the appropriate dialect automatically.


[View source]
def id(db : DBHandle) : String #

The database's id, made at random the first time it's asked for. Index files record it, so one left over from another database isn't taken for this one's.


[View source]
def init(db : DB::Database) #

Initialize Memo schema in provided database

Uses the dialect attached to the db connection to generate the correct DDL for the backend (SQLite or PostgreSQL), then migrates a database written by an earlier version (see Migration). Safe to call multiple times (uses IF NOT EXISTS)


[View source]
def load_schema(db : DB::Database) #

Load memo schema into the provided database (embedded mode) Safe to call multiple times (uses IF NOT EXISTS)


[View source]
def sqlite_url(path : String) : String #

Connection URL for a SQLite file. busy_timeout makes a connection wait up to 5 s for another's write lock instead of failing at once.


[View source]
def transaction(db : DBHandle, & : DB::Connection -> ) #

Run the block in a transaction, yielding the connection it holds.

Every statement in the block must go through the yielded connection (or its memo_queries). Statements sent to the pool run on another connection and commit on their own, outside the transaction.

Given a connection (already inside a transaction), joins it.


[View source]