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.cractive_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
-
.bootstrap_schema(schema : Schema) : Migrator
Quick schema bootstrap from existing database
-
.build_migrator(schema : Schema, custom_config : MigratorConfig | Nil = nil) : Migrator
Create a migrator using current configuration
-
.build_schema(name : Symbol, &) : Schema
Create a schema with smart defaults
-
.cache_on(enabled : Bool = true) : Nil
Quick cache enable/disable
-
.cache_on? : Bool
Check if cache is enabled
-
.cache_stats : Hash(String, String | Int32 | Int64 | Float64 | Bool)
Get cache statistics
-
.cache_summary : String
Get cache performance summary
-
.config : Configure::Config
Get current configuration (read-only access)
-
.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 -
.end_request_cache : Nil
End request-scoped caching.
-
.fragment_cache : CQL::Cache::FragmentCache
Create fragment cache instance
-
.memory_cache : CQL::Cache::MemoryCache
Create memory cache instance
-
.migrator_config(**args) : MigratorConfig
Create migrator configuration
-
.migrator_config_for(env : String) : MigratorConfig
Create environment-specific migrator configuration
-
.raw(sql : String, *positional, **named) : Expression::ConditionBuilder
A safe SQL fragment as a condition, e.g.
-
.request_cache_tracking? : Bool
Whether request-scoped caching starts requests:
cache.onandcache.request_cache. -
.reset_cache! : Nil
Reset cache statistics
-
.reset_config! : Nil
Reset configuration to defaults
-
.start_request_cache(request_id : String | Nil = nil) : Nil
Start request-scoped caching
-
.verify_schema(schema : Schema, auto_fix : Bool = false) : Bool
Whether the schema file matches the database; with
auto_fix(andauto_sync) a stale file is rewritten instead. -
.with_request_cache(request_id : String | Nil = nil, &)
Execute block with request-scoped caching.
Class Method Detail
Quick schema bootstrap from existing database
Create a migrator using current configuration
Create a schema with smart defaults
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
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.
Create environment-specific migrator configuration
A safe SQL fragment as a condition, e.g. where { raw("lower(email) = ?", e) & ... }.
Whether request-scoped caching starts requests: cache.on and cache.request_cache.
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.
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.