module CQL

Overview

ULID-compatible ID generator using Time.utc This provides a simple ULID-like implementation that works with modern Crystal

Defined in:

active_record/association_registry.cr
active_record/attributes.cr
active_record/bulk_insert.cr
active_record/callbacks.cr
active_record/definition.cr
active_record/deleteable.cr
active_record/dependents.cr
active_record/dirty_tracking.cr
active_record/dsl/column.cr
active_record/id_chunks.cr
active_record/identifyable.cr
active_record/insertable.cr
active_record/model.cr
active_record/optimistic_locking.cr
active_record/pagination.cr
active_record/persistence.cr
active_record/query_builder.cr
active_record/queryable.cr
active_record/relations.cr
active_record/relations/many_collection.cr
active_record/schema_validator.cr
active_record/scopes.cr
active_record/soft_deletable.cr
active_record/timestamp_manager.cr
active_record/transactional.cr
active_record/typed_columns.cr
active_record/updateable.cr
active_record/validations.cr
alter_table.cr
base_column.cr
cache/cache.cr
cache/cache_entry.cr
cache/cache_interface.cr
cache/cache_stats.cr
cache/cache_store.cr
cache/fragment_cache.cr
cache/invalidation_strategies.cr
cache/memory_cache.cr
cache/middleware.cr
cache/redis_cache.cr
cache/request_query_cache.cr
column.cr
compat.cr
compound_query.cr
configure.cr
configure/cache_config.cr
connection_source.cr
constraint.cr
converters/jsonb_converter.cr
converters/uuid_converter.cr
cql.cr
delete.cr
derived_table.cr
exceptions.cr
executable.cr
executor.cr
expression/raw.cr
foreign_key.cr
identifier.cr
index.cr
insert.cr
merge_query.cr
migrations.cr
operation_kind.cr
pool_stats.cr
prepared_select.cr
primary_key.cr
query.cr
quoted_name.cr
repository.cr
rollback_hooks.cr
schema.cr
schema_dump.cr
table.cr
telemetry.cr
ulid_compat.cr
update.cr
window_builder.cr

Class Method Summary

Class Method Detail

def self.bootstrap_schema(schema : Schema) : Migrator #

Quick schema bootstrap from existing database


[View source]
def self.build_migrator(schema : Schema, custom_config : MigratorConfig | Nil = nil) : Migrator #

Create a migrator using current configuration


[View source]
def self.build_schema(name : Symbol, &) : Schema #

Create a schema with smart defaults


[View source]
def self.cache_on(enabled : Bool = true) : Nil #

Quick cache enable/disable


[View source]
def self.cache_on? : Bool #

Check if cache is enabled


[View source]
def self.cache_stats : Hash(String, String | Int32 | Int64 | Float64 | Bool) #

Get cache statistics


[View source]
def self.cache_summary : String #

Get cache performance summary


[View source]
def self.config : Configure::Config #

Get current configuration (read-only access)


[View source]
def self.configure(& : Configure::Config -> ) #

Minimal Development Setup

CQL.configure do |c|
  c.db = "postgresql://localhost/myapp"
end
# With CRYSTAL_ENV=development this also turns on SQL logging

Production Ready

CQL.configure do |c|
  c.db = ENV["DATABASE_URL"]
  c.env = "production"
  c.pool_size = 25
  c.sql_logging = false # Disable SQL logging
  c.cache.on = true     # Enable caching
end

Custom Configuration

CQL.configure do |c|
  c.db = "postgresql://localhost/myapp"
  c.sql_logging_colorize = false # Disable colors
  c.cache.on = true              # Enable caching
end

[View source]
def self.end_request_cache : Nil #

End request-scoped caching. Not gated on the switches, so a request started before one of them was turned off still ends; on a fiber without a request it does nothing. With the switches off it still ends a request someone else started on this fiber: prefer .with_request_cache, which ends only what it started.


[View source]
def self.fragment_cache : CQL::Cache::FragmentCache #

Create fragment cache instance


[View source]
def self.memory_cache : CQL::Cache::MemoryCache #

Create memory cache instance


[View source]
def self.migrator_config(**args) : MigratorConfig #

Create migrator configuration


[View source]
def self.migrator_config_for(env : String) : MigratorConfig #

Create environment-specific migrator configuration


[View source]
def self.raw(sql : String, *positional, **named) : Expression::ConditionBuilder #

A safe SQL fragment as a condition, e.g. where { raw("lower(email) = ?", e) & ... }.


[View source]
def self.request_cache_tracking? : Bool #

Whether request-scoped caching starts requests: cache.on and cache.request_cache.


[View source]
def self.reset_cache! : Nil #

Reset cache statistics


[View source]
def self.reset_config! : Nil #

Reset configuration to defaults


[View source]
def self.start_request_cache(request_id : String | Nil = nil) : Nil #

Start request-scoped caching


[View source]
def self.verify_schema(schema : Schema, auto_fix : Bool = false) : Bool #

Whether the schema file matches the database; with auto_fix (and auto_sync) a stale file is rewritten instead. Uses a plain migrator: .build_migrator rewrites a stale file before the check when .verify_schema and auto_sync are on.


[View source]
def self.with_request_cache(request_id : String | Nil = nil, &) #

Execute block with request-scoped caching. The switches are read once: the block's request is started and ended only when they were on at the start, so a request started outside the block is never ended by it.


[View source]