source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/associations/one_to_many.rb | Ruby | mit | 220 | release-3.7 | 818 | # frozen_string_literal: true
require 'rom/associations/one_to_many'
require 'rom/sql/associations/core'
require 'rom/sql/associations/self_ref'
module ROM
module SQL
module Associations
class OneToMany < ROM::Associations::OneToMany
include Associations::Core
include Associations::SelfRef... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/schema/attributes_inferrer.rb | Ruby | mit | 220 | release-3.7 | 1,206 | # frozen_string_literal: true
require 'dry/core/class_attributes'
module ROM
module SQL
class Schema < ROM::Schema
# @api private
class AttributesInferrer
extend Dry::Core::ClassAttributes
extend Initializer
defines :type_builders
CONSTRAINT_DB_TYPE = 'add_constrain... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/schema/type_builder.rb | Ruby | mit | 220 | release-3.7 | 2,955 | # frozen_string_literal: true
module ROM
module SQL
class Schema
# @api private
class TypeBuilder
extend Dry::Core::ClassAttributes
defines :registry
def self.register(db_type, builder)
registry[db_type] = builder
end
def self.[](db_type)
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/schema/dsl.rb | Ruby | mit | 220 | release-3.7 | 869 | # frozen_string_literal: true
require 'rom/sql/schema/index_dsl'
module ROM
module SQL
class Schema < ROM::Schema
# Specialized schema DSL with SQL-specific features
#
# @api public
class DSL < ROM::Schema::DSL
# @!attribute [r] index_dsl
# @return [IndexDSL] Index DSL ... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/schema/index_dsl.rb | Ruby | mit | 220 | release-3.7 | 1,132 | # frozen_string_literal: true
module ROM
module SQL
class Schema < ROM::Schema
# @api public
class IndexDSL
extend Initializer
option :attr_class
attr_reader :registry
# @api private
def initialize(*, **, &)
super
@registry = []
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/schema/inferrer.rb | Ruby | mit | 220 | release-3.7 | 5,075 | # frozen_string_literal: true
require 'rom/sql/schema/type_builder'
require 'rom/sql/schema/attributes_inferrer'
require 'rom/sql/attribute'
module ROM
module SQL
class Schema < ROM::Schema
# @api private
class Inferrer < ROM::Schema::Inferrer
defines :type_builders
attributes_infer... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/relation/writing.rb | Ruby | mit | 220 | release-3.7 | 3,847 | # frozen_string_literal: true
module ROM
module SQL
class Relation < ROM::Relation
module Writing
# Add upsert option (only PostgreSQL >= 9.5)
# Uses internal Sequel implementation
# Default - ON CONFLICT DO NOTHING
# more options: http://sequel.jeremyevans.net/rdoc-adapters... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/relation/reading.rb | Ruby | mit | 220 | release-3.7 | 35,189 | # frozen_string_literal: true
require 'rom/support/inflector'
require 'rom/sql/join_dsl'
module ROM
module SQL
class Relation < ROM::Relation
# Query API for SQL::Relation
#
# @api public
#
# rubocop:disable Metrics/ModuleLength
module Reading
# Row-level lock modes
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres.rb | Ruby | mit | 220 | release-3.7 | 340 | # frozen_string_literal: true
require 'rom/sql/extensions/postgres/commands'
require 'rom/sql/extensions/postgres/types'
require 'rom/sql/extensions/postgres/type_builder'
require 'rom/sql/extensions/postgres/type_serializer'
require 'rom/plugins/relation/sql/postgres/explain'
require 'rom/plugins/relation/sql/postgre... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/active_support_notifications.rb | Ruby | mit | 220 | release-3.7 | 576 | # frozen_string_literal: true
require 'sequel/database/logging'
require 'active_support/notifications'
module ROM
module SQL
module ActiveSupportInstrumentation
def log_connection_yield(sql, _conn, args = nil)
ActiveSupport::Notifications.instrument(
'sql.rom',
sql: sql,
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/rails_log_subscriber.rb | Ruby | mit | 220 | release-3.7 | 1,206 | # frozen_string_literal: true
require 'active_support/log_subscriber'
module ROM
module SQL
class RailsLogSubscriber < ActiveSupport::LogSubscriber
as_version =
begin
require 'active_support/gem_version'
ActiveSupport.gem_version
rescue LoadError
nil
e... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/type_serializer.rb | Ruby | mit | 220 | release-3.7 | 1,457 | # frozen_string_literal: true
module ROM
module SQL
module Postgres
# @api private
class TypeSerializer < ROM::SQL::TypeSerializer
mapping(
mapping.merge(
SQL::Types::String => 'text',
Types::UUID => 'uuid',
Types::XML => 'xml',
Types:... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/type_builder.rb | Ruby | mit | 220 | release-3.7 | 2,470 | # frozen_string_literal: true
module ROM
module SQL
module Postgres
class TypeBuilder < Schema::TypeBuilder
defines :db_numeric_types, :db_type_mapping, :db_array_type_matcher
db_numeric_types [
'smallint', 'integer', 'bigint',
'decimal', 'numeric', 'real',
'd... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/types.rb | Ruby | mit | 220 | release-3.7 | 1,159 | # frozen_string_literal: true
require 'sequel/core'
require 'rom/sql/type_extensions'
Sequel.extension(:pg_hstore)
module ROM
module SQL
module Postgres
module Types
def self.Type(name, type = yield)
type.meta(db_type: name, database: 'postgres')
end
UUID = Type('uuid'... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/commands.rb | Ruby | mit | 220 | release-3.7 | 5,434 | # frozen_string_literal: true
require 'rom/sql/commands/create'
require 'rom/sql/commands/update'
module ROM
module SQL
module Postgres
module Commands
# @api private
module Core
private
# Common dataset used by create/update commands
#
# @return [S... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/types/ltree.rb | Ruby | mit | 220 | release-3.7 | 13,869 | # frozen_string_literal: true
require 'rom/types/values'
module ROM
module SQL
module Postgres
# @api public
#
# rubocop:disable Metrics/ModuleLength
module Types
# @see https://www.postgresql.org/docs/current/static/ltree.html
LTree = Type('ltree') do
SQL::Typ... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/types/json.rb | Ruby | mit | 220 | release-3.7 | 10,270 | # frozen_string_literal: true
require 'sequel/core'
require 'singleton'
Sequel.extension(:pg_json, :pg_json_ops)
module ROM
module SQL
module Postgres
module Types
JSONRead = (SQL::Types::Array | SQL::Types::Hash).constructor do |value|
if value.respond_to?(:to_hash)
value.t... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/types/geometric.rb | Ruby | mit | 220 | release-3.7 | 4,469 | # frozen_string_literal: true
module ROM
module SQL
module Postgres
module Values
Point = ::Struct.new(:x, :y)
Line = ::Struct.new(:a, :b, :c)
Circle = ::Struct.new(:center, :radius)
Box = ::Struct.new(:upper_right, :lower_left)
LineSegment = ::Struct.new(:begin,... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/types/network.rb | Ruby | mit | 220 | release-3.7 | 680 | # frozen_string_literal: true
require 'ipaddr'
module ROM
module SQL
module Postgres
module Types
IPAddress = Type('inet') do
read = SQL::Types.Constructor(IPAddr) { |ip| ::IPAddr.new(ip.to_s) }
SQL::Types.Constructor(::IPAddr, &:to_s).meta(read: read)
end
IPN... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/types/range.rb | Ruby | mit | 220 | release-3.7 | 6,140 | # frozen_string_literal: true
require 'sequel/core'
Sequel.extension(:pg_range, :pg_range_ops)
module ROM
module SQL
module Postgres
module Values
Range = ::Struct.new(:lower, :upper, :bounds) do
def initialize(lower, upper, bounds = :'[)')
super
end
def... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/types/array_types.rb | Ruby | mit | 220 | release-3.7 | 1,937 | # frozen_string_literal: true
require 'rom/sql/type_extensions'
module ROM
module SQL
module Postgres
module Types
# @api private
class ArrayTypes
attr_reader :elements
attr_reader :constructor
attr_reader :base_write_type
attr_reader :base_read_t... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/postgres/types/array.rb | Ruby | mit | 220 | release-3.7 | 5,018 | # frozen_string_literal: true
require 'sequel/core'
Sequel.extension(:pg_array, :pg_array_ops)
require 'rom/sql/extensions/postgres/types/array_types'
module ROM
module SQL
module Postgres
module Types
Array = SQL::Types::Array
ArrayRead = Array.constructor { |v| v.respond_to?(:to_ary) ... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/sqlite/type_builder.rb | Ruby | mit | 220 | release-3.7 | 452 | # frozen_string_literal: true
module ROM
module SQL
module SQLite
class TypeBuilder < Schema::TypeBuilder
NO_TYPE = EMPTY_STRING
# @api private
def map_type(_, db_type, **_kw)
if db_type.eql?(NO_TYPE)
ROM::SQL::Types::SQLite::Any
else
sup... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/sqlite/types.rb | Ruby | mit | 220 | release-3.7 | 266 | # frozen_string_literal: true
require 'dry-types'
module ROM
module SQL
module SQLite
module Types
Any = ::ROM::SQL::Types::Any
Object = Any
end
end
module Types
SQLite = ::ROM::SQL::SQLite::Types
end
end
end |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/extensions/mysql/type_builder.rb | Ruby | mit | 220 | release-3.7 | 685 | # frozen_string_literal: true
require 'rom/sql/schema/attributes_inferrer'
module ROM
module SQL
module MySQL
class TypeBuilder < Schema::TypeBuilder
defines :db_type_mapping
db_type_mapping(
'tinytext' => Types::String,
'text' => Types::String,
'mediumtext' ... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/spec/support.rb | Ruby | mit | 220 | release-3.7 | 484 | # frozen_string_literal: true
if defined? JRUBY_VERSION
USING_JRUBY = true
else
USING_JRUBY = false
end
if USING_JRUBY
SEQUEL_TEST_DB_URI = 'jdbc:sqlite::memory:'
else
SEQUEL_TEST_DB_URI = 'sqlite::memory'
end
DB = Sequel.connect(SEQUEL_TEST_DB_URI)
def seed(db = DB)
db.run('CREATE TABLE users (id INTEGER... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/migration/recorder.rb | Ruby | mit | 220 | release-3.7 | 566 | # frozen_string_literal: true
module ROM
module SQL
module Migration
# @api private
class Recorder
attr_reader :operations
def initialize(&)
@operations = []
instance_exec(&) if block_given?
end
private
def respond_to_missing?(_m, _inclu... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/migration/writer.rb | Ruby | mit | 220 | release-3.7 | 1,706 | # frozen_string_literal: true
require 'rom/sql/migration/recorder'
module ROM
module SQL
module Migration
# @api private
class Writer
MIGRATION_BEGIN = "ROM::SQL.migration do\n change do"
MIGRATION_END = "\n end\nend\n"
attr_reader :yield_migration
def initialize(... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/migration/inline_runner.rb | Ruby | mit | 220 | release-3.7 | 519 | # frozen_string_literal: true
module ROM
module SQL
module Migration
# @api private
class InlineRunner < BasicObject
extend Initializer
param :connection
def migration
yield(connection)
end
private
def method_missing(m, ...)
conn... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/migration/schema_diff.rb | Ruby | mit | 220 | release-3.7 | 7,224 | # frozen_string_literal: true
require 'rom/sql/type_serializer'
module ROM
module SQL
module Migration
# @api private
class SchemaDiff
extend Initializer
param :database_type
option :type_serializer, default: -> { ROM::SQL::TypeSerializer[database_type] }
class Tab... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/migration/runner.rb | Ruby | mit | 220 | release-3.7 | 3,816 | # frozen_string_literal: true
module ROM
module SQL
module Migration
# @api private
class Runner
attr_reader :writer
def initialize(writer)
@writer = writer
end
def call(changes)
changes.each { |diff| apply_schema(diff) }
changes.each { ... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/migration/migrator.rb | Ruby | mit | 220 | release-3.7 | 2,684 | # frozen_string_literal: true
require 'pathname'
require 'rom/types'
require 'rom/initializer'
require 'rom/sql/migration/runner'
require 'rom/sql/migration/inline_runner'
require 'rom/sql/migration/writer'
module ROM
module SQL
module Migration
# @api private
class Migrator
extend Initial... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/plugin/pagination.rb | Ruby | mit | 220 | release-3.7 | 3,734 | # frozen_string_literal: true
require 'rom/initializer'
module ROM
module SQL
module Plugin
# Pagination plugin for Relations
#
# @api public
module Pagination
# Pager object provides the underlying pagination API for relations
#
# @api public
class Pager
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/plugin/nullify.rb | Ruby | mit | 220 | release-3.7 | 1,135 | # frozen_string_literal: true
module ROM
module SQL
module Plugin
# Nullify relation by
#
# @api public
module Nullify
if defined? JRUBY_VERSION
# Returns a relation that will never issue a query to the database. It
# implements the null object pattern for rela... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/plugin/associates.rb | Ruby | mit | 220 | release-3.7 | 5,191 | # frozen_string_literal: true
require 'rom/sql/associations'
module ROM
module SQL
module Plugin
# Make a command that automaticaly sets FK attribute on input tuples
#
# @api private
module Associates
class AssociateOptions
attr_reader :name
attr_reader :asso... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/commands/create.rb | Ruby | mit | 220 | release-3.7 | 1,750 | # frozen_string_literal: true
require 'rom/sql/commands/error_wrapper'
module ROM
module SQL
module Commands
# SQL create command
#
# @api public
class Create < ROM::Commands::Create
adapter :sql
include ErrorWrapper
use :associates
use :schema
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/commands/delete.rb | Ruby | mit | 220 | release-3.7 | 535 | # frozen_string_literal: true
require 'rom/sql/commands/error_wrapper'
module ROM
module SQL
module Commands
# SQL delete command
#
# @api public
class Delete < ROM::Commands::Delete
adapter :sql
include ErrorWrapper
# Deletes tuples from a relation
#
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/commands/error_wrapper.rb | Ruby | mit | 220 | release-3.7 | 562 | # frozen_string_literal: true
module ROM
module SQL
module Commands
# Shared error handler for all SQL commands
#
# @api private
module ErrorWrapper
# Handle Sequel errors and re-raise ROM-specific errors
#
# @return [Hash, Array<Hash>]
#
# @raise S... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/sql/commands/update.rb | Ruby | mit | 220 | release-3.7 | 1,381 | # frozen_string_literal: true
require 'rom/sql/commands/error_wrapper'
module ROM
module SQL
module Commands
# Update command
#
# @api public
class Update < ROM::Commands::Update
adapter :sql
include ErrorWrapper
use :schema
use :associates
afte... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | lib/rom/types/values.rb | Ruby | mit | 220 | release-3.7 | 425 | # frozen_string_literal: true
require 'rom/sql/types'
module ROM
module Types
module Values
class TreePath < ::Struct.new(:value, :separator) # rubocop:disable Style/StructInheritance
# @api public
def self.new(value, separator = '.')
super
end
# @api public
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/spec_helper.rb | Ruby | mit | 220 | release-3.7 | 3,218 | # frozen_string_literal: true
require_relative 'support/coverage'
require 'warning'
Warning.ignore(/\$SAFE/)
Warning.ignore(/sequel/)
Warning.ignore(/mysql2/)
Warning.ignore(/rake/)
Warning.ignore(/rspec-core/)
Warning.ignore(/__FILE__/)
Warning.ignore(/__LINE__/)
Warning.ignore(/codacy/)
Warning.ignore(/zeitwerk/)
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/support/env_helper.rb | Ruby | mit | 220 | release-3.7 | 383 | # frozen_string_literal: true
module ENVHelper
def db?(type, example)
example.metadata[type]
end
def postgres?(example)
db?(:postgres, example)
end
def mysql?(example)
db?(:mysql, example)
end
def sqlite?(example)
db?(:sqlite, example)
end
def oracle?(example)
db?(:oracle, exa... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/support/warnings.rb | Ruby | mit | 220 | release-3.7 | 248 | # frozen_string_literal: true
# this file is managed by rom-rb/devtools project
require "warning"
Warning.ignore(%r{rspec/core})
Warning.ignore(%r{rspec/mocks})
Warning.ignore(/codacy/)
Warning[:experimental] = false if Warning.respond_to?(:[]) |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/support/test_configuration.rb | Ruby | mit | 220 | release-3.7 | 416 | # frozen_string_literal: true
require 'rom/configuration'
class TestConfiguration < ROM::Configuration
def relation(name, *, &)
if registered_relation_names.include?(name)
setup.relation_classes.delete_if do |klass|
klass.relation_name.relation == name
end
end
super
end
def regi... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/support/coverage.rb | Ruby | mit | 220 | release-3.7 | 307 | # frozen_string_literal: true
# this file is managed by rom-rb/devtools
if ENV["COVERAGE"] == "true"
require "simplecov"
require "simplecov-cobertura"
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
SimpleCov.start do
add_filter "/spec/"
enable_coverage :branch
end
end |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/support/helpers.rb | Ruby | mit | 220 | release-3.7 | 1,250 | # frozen_string_literal: true
module Helpers
def assoc_name(*)
ROM::Relation::Name[*]
end
def define_schema(name, attrs = [])
relation_name = ROM::Relation::Name.new(name)
ROM::SQL::Schema.define(
relation_name,
attributes: attrs.map do |attr_name, type|
ROM::SQL::Schema.build_at... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/extensions/sqlite/types_spec.rb | Ruby | mit | 220 | release-3.7 | 331 | # frozen_string_literal: true
RSpec.describe 'ROM::SQL::Types' do
describe 'ROM::SQL::Types::SQLite::Object' do
let(:type) { ROM::SQL::Types::SQLite::Object }
it 'passes an object of any type' do
[Object.new, 1, true, BasicObject.new].each do |obj|
expect(type[obj]).to be obj
end
end... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/extensions/postgres/integration_spec.rb | Ruby | mit | 220 | release-3.7 | 3,447 | # frozen_string_literal: true
RSpec.describe 'PostgreSQL extension', :postgres do
include_context 'database setup'
before do
conn.drop_table?(:pg_people)
conn.drop_table?(:people)
end
context 'with arrays' do
before do
conn.create_table :pg_people do
primary_key :id
String :... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/extensions/postgres/types_meta_spec.rb | Ruby | mit | 220 | release-3.7 | 1,105 | # frozen_string_literal: true
RSpec.describe 'ROM::SQL::Postgres::Types' do
it 'has the correct meta db_type' do
{
'uuid' => ROM::SQL::Postgres::Types::UUID,
'hstore' => ROM::SQL::Postgres::Types::HStore,
'bytea' => ROM::SQL::Postgres::Types::Bytea,
'money' => ROM::SQL::Postgres::Types::M... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/extensions/postgres/attribute_spec.rb | Ruby | mit | 220 | release-3.7 | 13,202 | # frozen_string_literal: true
RSpec.describe 'ROM::SQL::Attribute', :postgres do
include_context 'database setup'
before do
conn.drop_table?(:pg_people)
conn.drop_table?(:people)
conf.relation(:people) do
schema(:pg_people, infer: true)
end
end
let(:people) { relations[:people] }
let... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/extensions/postgres/type_serializer_spec.rb | Ruby | mit | 220 | release-3.7 | 1,585 | # frozen_string_literal: true
RSpec.describe ROM::SQL::TypeSerializer[:postgres] do
subject(:serializer) { ROM::SQL::TypeSerializer[:postgres] }
it 'serializes PG types' do
types = {
'uuid' => ROM::SQL::Postgres::Types::UUID,
'money' => ROM::SQL::Postgres::Types::Money,
'bytea' => ROM::SQL::... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/extensions/postgres/types_spec.rb | Ruby | mit | 220 | release-3.7 | 9,822 | # frozen_string_literal: true
require 'securerandom'
RSpec.describe 'ROM::SQL::Postgres::Types' do
let(:values) { ROM::SQL::Postgres::Values }
describe 'ROM::SQL::Types::PG::JSON' do
it 'coerces to pg json hash' do
input = { foo: 'bar' }
expect(ROM::SQL::Types::PG::JSON[input]).to eql(Sequel.pg_... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/extensions/postgres/attribute/range_spec.rb | Ruby | mit | 220 | release-3.7 | 5,392 | # frozen_string_literal: true
RSpec.describe 'ROM::SQL::Attribute', :postgres do
include_context 'database setup'
def create_ranges_table(db_type, values)
conn.create_table :pg_ranges do
primary_key :id
text :name
send(db_type, :range)
end
conf.relation(:pg_ranges) do
schema(... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/extensions/postgres/attribute/array_spec.rb | Ruby | mit | 220 | release-3.7 | 1,204 | # frozen_string_literal: true
RSpec.describe 'ROM::SQL::Attribute / PG array', :postgres do
subject(:relation) { relations[:pg_arrays] }
include_context 'database setup'
before do
conf.relation(:pg_arrays) do
schema(infer: true)
end
end
after do
conn.drop_table(:pg_arrays)
end
conte... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/schema_spec.rb | Ruby | mit | 220 | release-3.7 | 728 | # frozen_string_literal: true
RSpec.describe ROM::SQL::Schema, :postgres do
describe '#primary_key' do
it 'returns primary key attributes' do
schema_proc = Class.new(ROM::Relation[:sql]).schema do
attribute :id, ROM::SQL::Types::Serial
end
schema = schema_proc.call
schema.finaliz... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/order_dsl_spec.rb | Ruby | mit | 220 | release-3.7 | 1,323 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ROM::SQL::OrderDSL, :postgres, helpers: true do
include_context 'database setup'
subject(:dsl) do
ROM::SQL::OrderDSL.new(schema)
end
let(:schema) do
define_schema(:users, id: ROM::SQL::Types::Serial, name: ROM::SQL::Types::String)
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/function_spec.rb | Ruby | mit | 220 | release-3.7 | 6,653 | # frozen_string_literal: true
require 'rom/sql/function'
RSpec.describe ROM::SQL::Function, :postgres do
include_context 'users'
subject(:func) { ROM::SQL::Function.new(type).meta(schema: users.schema) }
let(:ds) { container.gateways[:default][:users] }
let(:type) { ROM::SQL::Types::Integer }
describe '#... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/migrator_spec.rb | Ruby | mit | 220 | release-3.7 | 992 | # frozen_string_literal: true
RSpec.describe ROM::SQL::Migration::Migrator, :postgres, skip_tables: true do
include_context 'database setup'
subject(:migrator) { ROM::SQL::Migration::Migrator.new(conn, **options) }
let(:options) { { path: TMP_PATH.join('test/migrations') } }
describe '#create_file' do
i... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/logger_spec.rb | Ruby | mit | 220 | release-3.7 | 337 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Logger', :postgres do
include_context 'database setup'
it 'sets up a logger for sequel' do
gateway = container.gateways[:default]
gateway.use_logger(LOGGER)
expect(gateway.logger).to be(LOGGER)
expect(conn.loggers).to include(L... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/projection_dsl_spec.rb | Ruby | mit | 220 | release-3.7 | 5,237 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ROM::SQL::ProjectionDSL, :postgres, helpers: true do
include_context 'database setup'
subject(:dsl) do
ROM::SQL::ProjectionDSL.new(schema)
end
let(:schema) do
define_schema(
:users,
id: ROM::SQL::Types::Serial,
name... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/attribute_spec.rb | Ruby | mit | 220 | release-3.7 | 4,643 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ROM::SQL::Attribute, :postgres do
include_context 'users and tasks'
let(:ds) { users.dataset }
describe '#is' do
context 'with a standard value' do
it 'returns a boolean expression' do
expect(users[:id].is(1).sql_literal(ds))... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/type_serializer_spec.rb | Ruby | mit | 220 | release-3.7 | 773 | # frozen_string_literal: true
require 'rom/sql/type_serializer'
RSpec.describe ROM::SQL::TypeSerializer do
subject(:serializer) { described_class.new }
it 'serializes data types' do
types = {
'integer' => ROM::SQL::Types::Integer,
'varchar' => ROM::SQL::Types::String,
'timestamp' => ROM::SQ... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/gateway_spec.rb | Ruby | mit | 220 | release-3.7 | 2,763 | # frozen_string_literal: true
require 'spec_helper'
require 'rom/lint/spec'
RSpec.describe ROM::SQL::Gateway, :postgres do
include_context 'users and tasks'
let(:gateway) { container.gateways[:default] }
it_behaves_like 'a rom gateway' do
let(:identifier) { :sql }
let(:gateway) { ROM::SQL::Gateway }
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/restriction_dsl_spec.rb | Ruby | mit | 220 | release-3.7 | 1,100 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ROM::SQL::RestrictionDSL, :sqlite, helpers: true do
include_context 'database setup'
subject(:dsl) do
ROM::SQL::RestrictionDSL.new(schema)
end
let(:schema) do
define_schema(:users, id: ROM::SQL::Types::Serial, name: ROM::SQL::Types::... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/migration_tasks_spec.rb | Ruby | mit | 220 | release-3.7 | 4,558 | # frozen_string_literal: true
require 'spec_helper'
namespace :db do
task :setup do
# noop
end
end
RSpec.describe 'MigrationTasks', :postgres, skip_tables: true do
include_context 'database setup'
let(:migrator) { container.gateways[:default].migrator }
let(:task) { nil }
before do
ROM::SQL::Ga... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/types_spec.rb | Ruby | mit | 220 | release-3.7 | 1,729 | # frozen_string_literal: true
require 'rom/sql/types'
RSpec.describe ROM::SQL::Types, :postgres do
describe ROM::SQL::Types::Blob do
it 'coerces strings to Sequel::SQL::Blob' do
input = 'sutin'
output = described_class[input]
expect(output).to be_instance_of(Sequel::SQL::Blob)
expect(ou... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/commands/create_spec.rb | Ruby | mit | 220 | release-3.7 | 831 | # frozen_string_literal: true
require 'rom/sql/commands/create'
RSpec.describe ROM::SQL::Commands::Create do
subject(:command) do
relations[:books].command(:create)
end
include_context 'database setup'
with_adapters do
after do
conn.drop_table?(:books)
end
describe '#call' do
be... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/gateway/new_spec.rb | Ruby | mit | 220 | release-3.7 | 468 | # frozen_string_literal: true
require 'rom/sql/gateway'
RSpec.describe ROM::SQL::Gateway, '#initialize' do
subject(:gateway) do
ROM::SQL::Gateway.new(uri)
end
context 'with option hash' do
let(:uri) do
{ adapter: 'sqlite',
database: ':memory:' }
end
it 'establishes connection' do... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/left_join_spec.rb | Ruby | mit | 220 | release-3.7 | 1,440 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#left_join' do
subject(:relation) { relations[:users] }
include_context 'users and tasks'
with_adapters do
it 'joins relations using left outer join' do
relation.insert id: 3, name: 'Jade'
result = relation
.left_join(:tasks,... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/read_spec.rb | Ruby | mit | 220 | release-3.7 | 666 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#read' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
let(:users) do
relation.read('SELECT name FROM users')
end
it 'returns results from raw SQL' do
expect(users).to ma... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/inspect_spec.rb | Ruby | mit | 220 | release-3.7 | 283 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#inspect' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
it 'includes dataset' do
expect(relation.inspect).to include('dataset')
end
end
end |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/inner_join_spec.rb | Ruby | mit | 220 | release-3.7 | 5,488 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#inner_join' do
subject(:relation) { relations[:users] }
let(:puzzles) { relations[:puzzles] }
include_context 'users and tasks'
with_adapters do
it 'joins relations using inner join' do
relation.insert id: 3, name: 'Jade'
result ... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/primary_key_spec.rb | Ruby | mit | 220 | release-3.7 | 703 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#primary_key' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
context 'with schema' do
it 'returns configured primary key from the schema' do
conf.relation(:users) do
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/by_pk_spec.rb | Ruby | mit | 220 | release-3.7 | 1,687 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#by_pk' do
include_context 'users and tasks'
with_adapters do
context 'with a single PK' do
subject(:relation) { relations[:users] }
it 'restricts a relation by its PK' do
expect(relation.by_pk(1).to_a).to eql([id: 1, name: 'Jan... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/pluck_spec.rb | Ruby | mit | 220 | release-3.7 | 479 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#pluck' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
it 'returns a list of values from a specific column' do
expect(relation.pluck(:id)).to eql([1, 2])
end
it 'returns a lis... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/invert_spec.rb | Ruby | mit | 220 | release-3.7 | 340 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#invert' do
subject(:relation) { relations[:users] }
include_context 'users and tasks'
with_adapters do
it 'delegates to dataset and returns a new relation' do
expect(relation.where(name: 'Jane').invert.to_a).to eql([{ id: 2, name: 'Joe' }]... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/as_hash_spec.rb | Ruby | mit | 220 | release-3.7 | 706 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#as_hash' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
before do
conf.relation(:users) do
schema(infer: true)
end
end
with_adapters do
it 'returns a hash with all tuples been the key the... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/select_append_spec.rb | Ruby | mit | 220 | release-3.7 | 1,189 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#select_append' do
subject(:relation) { relations[:tasks] }
include_context 'users and tasks'
with_adapters do
it 'appends new columns' do
selected = relation.select(:id).select_append(:title)
expect(selected.schema.map(&:name)).to e... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/import_spec.rb | Ruby | mit | 220 | release-3.7 | 2,000 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#import' do
subject(:relation) { relations[:users] }
include_context 'users'
let(:source) { relations[:users_for_loading] }
with_adapters(:postgres) do
context 'within a single gateway' do
before do
conn.drop_table?(:users_for_lo... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/where_spec.rb | Ruby | mit | 220 | release-3.7 | 5,777 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#where' do
subject(:relation) { relations[:tasks].select(:id, :title) }
include_context 'users and tasks'
with_adapters do
context 'without :read types' do
it 'restricts relation using provided conditions' do
expect(relation.where(i... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/exist_predicate_spec.rb | Ruby | mit | 220 | release-3.7 | 718 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#exist?' do
include_context 'users and tasks'
subject(:relation) { users }
with_adapters do
it 'returns true if relation has at least one tuple' do
expect(relation.exist?).to be(true)
end
it 'returns false if relation is empty' do
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/having_spec.rb | Ruby | mit | 220 | release-3.7 | 642 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#having' do
subject(:relation) do
relations[:users]
.inner_join(:tasks, user_id: :id)
.qualified
.select_group(:id, :name)
.select_append { integer::count(:tasks).as(:task_count) }
end
include_context 'users and tasks'
w... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/qualified_spec.rb | Ruby | mit | 220 | release-3.7 | 947 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#qualified' do
subject(:relation) { relations[:users] }
include_context 'users and tasks'
with_adapters do
it 'qualifies all attributes' do
qualified = relation.qualified
expect(qualified.schema.all?(&:qualified?)).to be(true)
en... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/dataset_spec.rb | Ruby | mit | 220 | release-3.7 | 1,503 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#dataset' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
let(:dataset) { container.gateways[:default].dataset(:users) }
with_adapters do
context 'with schema' do
before do
conf.relation(:use... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/max_spec.rb | Ruby | mit | 220 | release-3.7 | 279 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#max' do
subject(:relation) { container.relations.users }
include_context 'users'
with_adapters do
it 'delegates to dataset and return value' do
expect(relation.max(:id)).to eql(2)
end
end
end |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/map_spec.rb | Ruby | mit | 220 | release-3.7 | 407 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#map' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
it 'yields tuples' do
result = relation.map { |tuple| tuple[:name] }
expect(result).to eql(%w[Jane Joe])
end
it 'plu... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/sum_spec.rb | Ruby | mit | 220 | release-3.7 | 265 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#sum' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
it 'returns a sum' do
expect(relation.sum(:id)).to eql(3)
end
end
end |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/prefix_spec.rb | Ruby | mit | 220 | release-3.7 | 680 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#prefix' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
before do
conf.relation(:users) do
schema(infer: true)
def sorted
order(:id)
end
end
end
with_adapters do
it 'p... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/unique_predicate_spec.rb | Ruby | mit | 220 | release-3.7 | 558 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#unique?' do
subject(:relation) { container.relations.tasks }
include_context 'users and tasks'
with_adapters do
before { relation.delete }
it 'returns true when there is only one tuple matching criteria' do
expect(relation.unique?(tit... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/fetch_spec.rb | Ruby | mit | 220 | release-3.7 | 689 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#fetch' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
describe '#fetch' do
it 'returns a single tuple identified by the pk' do
expect(relation.fetch(1)).to eql(id: 1, name: 'J... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/assoc_spec.rb | Ruby | mit | 220 | release-3.7 | 2,175 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ROM::SQL::Relation do
include_context 'users and tasks'
context 'with has_many' do
subject(:users) { relations[:users] }
let(:tasks) { relations[:tasks] }
before do
conf.relation(:users) do
schema(infer: true) do
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/rename_spec.rb | Ruby | mit | 220 | release-3.7 | 523 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#rename' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
before do
conf.relation(:users) do
schema(infer: true)
def sorted
order(:id)
end
end
end
with_adapters do
it 'p... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/min_spec.rb | Ruby | mit | 220 | release-3.7 | 265 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#min' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
it 'returns a min' do
expect(relation.min(:id)).to eql(1)
end
end
end |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/union_spec.rb | Ruby | mit | 220 | release-3.7 | 2,347 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#union' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
before do
conf.relation(:tasks) do
schema(infer: true) do
associations do
has_many :task_tags
end
end
end
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/exclude_spec.rb | Ruby | mit | 220 | release-3.7 | 336 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#exclude' do
subject(:relation) { relations[:users] }
include_context 'users and tasks'
with_adapters do
it 'delegates to dataset and returns a new relation' do
expect(relation.exclude(name: 'Jane').to_a).to eql([{ id: 2, name: 'Joe' }])
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/associations_spec.rb | Ruby | mit | 220 | release-3.7 | 737 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#associations' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
with_adapters do
context 'with schema' do
it 'returns configured primary key from the schema' do
conf.relation(:users) do
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/group_spec.rb | Ruby | mit | 220 | release-3.7 | 2,132 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#group' do
subject(:relation) { relations[:users] }
let(:notes) { relations[:notes] }
include_context 'users and tasks'
with_adapters do
it 'groups by provided attribute name' do |example|
# Oracle doesn't support concise GROUP BY
... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/project_spec.rb | Ruby | mit | 220 | release-3.7 | 1,028 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#project' do
subject(:relation) { container.relations.users }
include_context 'users and tasks'
before do
conf.relation(:users) do
schema(infer: true)
def sorted
order(:id)
end
end
end
with_adapters do
it '... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/batch_spec.rb | Ruby | mit | 220 | release-3.7 | 1,019 | # frozen_string_literal: true
RSpec.describe ROM::Relation, '#each_batch', seeds: false do
include_context 'users and tasks'
context 'single-column PK' do
subject(:relation) { relations[:users] }
before do
7.times do |i|
conn[:users].insert name: "User #{i + 1}"
end
end
with_... |
github | rom-rb/rom-sql | https://github.com/rom-rb/rom-sql | spec/unit/relation/instrument_spec.rb | Ruby | mit | 220 | release-3.7 | 2,044 | # frozen_string_literal: true
RSpec.describe ROM::SQL::Relation, '#instrument', :sqlite do
include_context 'database setup'
subject(:relation) do
relations[:users]
end
let(:notifications) do
Class.new do
attr_reader :logs
def initialize
@logs = []
end
def instrument(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.