Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 18 20:33

    dependabot[bot] on bundler

    (compare)

  • Jan 18 20:33
    dependabot[bot] closed #344
  • Jan 18 20:33
    dependabot[bot] commented #344
  • Jan 18 20:33
    dependabot[bot] labeled #350
  • Jan 18 20:33
    dependabot[bot] labeled #350
  • Jan 18 20:33
    dependabot[bot] opened #350
  • Jan 18 20:33

    dependabot[bot] on bundler

    Bump rack from 2.2.3 to 2.2.6.2… (compare)

  • Dec 30 2022 13:08

    repobot-file-sync[bot] on main

    Update .repobot.yml from rom-rb… (compare)

  • Dec 30 2022 13:07

    solnic on main

    Update and rename .action_hero.… (compare)

  • Dec 20 2022 13:08
    ginjo starred rom-rb/rom-sql
  • Dec 17 2022 07:06

    flash-gordon on master

    Upgrade ROM-yaml Merge pull request #17 from Int… (compare)

  • Dec 17 2022 07:06
    flash-gordon closed #17
  • Dec 16 2022 14:24
    alex-lairan commented #163
  • Dec 16 2022 14:08
    alex-lairan opened #17
  • Dec 16 2022 14:05
  • Dec 10 2022 16:11
    dependabot[bot] labeled #349
  • Dec 10 2022 16:11
    dependabot[bot] labeled #349
  • Dec 10 2022 16:11

    dependabot[bot] on npm_and_yarn

    Bump qs from 6.5.2 to 6.5.3 Bu… (compare)

  • Dec 10 2022 16:11
    dependabot[bot] opened #349
  • Dec 08 2022 21:32
    andreibondarev starred rom-rb/rom-sql
Peter Solnica
@solnic
@endash my current thinking is to make it as close to sql syntax as possible
Christopher Swasey
@endash
I'm in favor of that insofar as there are two paths that are cleanly separate: a programmatic "ruby API" that is explicit and clear about what structures it's creating on the ruby side, and the more magic DSL that apes SQL on the other with some confinement principle. I just noticed for instance that when function(...) was first mentioned the syntax had switched from select() to select { }. That's a good switch point, IMO: inside the block you can do something like select { array_agg(:foo).as(:foobar) }, outside the block you're back in Kansas. Right now it's mixed: select {} puts you directly into the DSL but still has programmatic APIs like function, and there are other entry points into the same DSL other than select {} so you have potential for "wait, where exactly is this defined?" cognitive discontinuity with select().
Peter Solnica
@solnic
@endash actually, you can use functions w/o the block syntax. there's Attribute#func
Christopher Swasey
@endash
This is a sketch of how I see things, albeit very addled since I've been knee deep on this axiomatic system notation syntax I've been working on for days:
# Currently, one pure DSL path, two mixed paths, one pure API-style path:

  # Get a ProjectionDSL, use type-first DSL magic
  select { array::array_agg(offer_type).as(:offer_types) }

  # Get a ProjectionDSL, use API-style factory
  select { function(:array_agg, :offer_type).as(:offer_types) }

  # Use API-style, get a ProjectionDSL
  select(offers[:offer_type].func { array::array_agg(:offer_type).as(:offer_types))

  # Use API-style, but manually construct `Function` API-style
  select(Function.new(ROM::SQL::Types::Any).array_agg(:offer_type).as(:offer_types))

# Two separate paths:

  # API-style, `function` is a convenience factory for a `Function`, minimally equiv. to the above example
  select(function(:array_agg, :offer_type).as(:offer_types))

  # DSL magic
  select { array_agg(:offer_type).as(:offer_types) }
Constantin Căpățînă
@drqCode
Below, I want to combine with tasks based on composite key (user_id, other_user_id), but it doesn't work as expected. How can I built the schema for tasks in order to combine based on composite key?
class Users < ROM::Relation[:sql]
  schema do
    attribute :user_id, Types::Int
    attribute :other_user_id, Types::Int
    primary_key :user_id, :other_user_id

    associations do
       has_many :tasks
    end
  end
end

class Tasks < ROM::Relation[:sql]
  schema do
    attribute :user_id, Types::ForeignKey(:users)
    attribute :other_user_id, Types::ForeignKey(:users)
  end
end

users.combine(:tasks).to_a # this result in a '... INNER JOIN users ON users.user_id = tasks.user_id WHERE ...'
Dawid Lenkiewicz
@dawidlenkiewicz

hey is there a way to drop and create database, something like:

    Rake::Task["db:drop"].invoke
    Rake::Task["db:create"].invoke

Or should I already have the db created when starting the app, because that's what I see in Sequel docs?

Christopher Swasey
@endash
Oh yes definitely the app should be independent of that sort of task
Dawid Lenkiewicz
@dawidlenkiewicz
ok thanks :) makes sense
Peter Solnica
@solnic
@drqCode you need to specify which foreign_key should be used so has_many :tasks, foreign_key: :other_user_id
Constantin Căpățînă
@drqCode
@solnic yes, but I wanted to specify composite foreign key..
For example, has_many tasks, foreign_key: [:user_id, :other_user_id]
Nikita Shilnikov
@flash-gordon
rom-sql supports composite FKs but rom itself doesn't support multi-key composition, one can create a fake key by, I dunno, concatenation of keys in SQL but this is a really nasty workaround
FWIW composite PKs and FKs especially is PITA
mostly because of poor support in DB tooling around
David Dawson
@DangerDawson
@flash-gordon I also have had issues with using composite primary/foreign keys for join tables and then referencing them with associations whilst using Hanami, would the advice be not to use composite primary keys if you plan on using the built in associations?
Nikita Shilnikov
@flash-gordon
well yes, that is the general advice on the subject. You can create a unique index so that you won't lose the guaranties you had with composite keys but indexes are not free, take space and slow down the insert. Usually, it's not a big deal but it always depends
from the rdbms perspective you should use its capabilities to the limit but the problem is the world doesn't end with rdbms. tl;dr I didn't find composite keys particularly useful even when I wrote a ton of pl/sql
David Dawson
@DangerDawson
I suppose it all depends on the database in question, as from what I can remember the innodb (MySQL) engine stores data locally to its primary keys, which gives you a nice performance boost if just using primary keys for lookups / joins
Nikita Shilnikov
@flash-gordon
good point, at the same time mysql has really poor support for composite pks itself. IIRC there's no way to fetch the PK value after insertion, it also was/is a complication for rom
rom's general pattern let's say
David Dawson
@DangerDawson
So the general advice would be to use composite primary / foreign keys if you are happy to fallback to writing raw SQL and you the extra performance is required, otherwise stick to using singular primary keys
Nikita Shilnikov
@flash-gordon
yes
Lairan
@alex-lairan
Dawid Lenkiewicz
@dawidlenkiewicz

Hey is it possible to have query like for example:

collection.where{(horsepower =~ 100..200) | (horsepower =~ 500..600)}

but doing it dynamically? When the horsepower number of ranges is not known ?

basically by having an array (of n elements) of ranges
Lairan
@alex-lairan
If so, how to connect ROM to a MongoDB database?
Vasily Kolesnikov
@v-kolesnikov
@alex-lairan It isn't dead, I use it in couple of projects in production.
Oskar Szrajer
@gotar
@dawidlenkiewicz
>> Range.new(*[100, 200])
=> 100..200
it's normal ruby code, nothing related to ROM
Lairan
@alex-lairan

@v-kolesnikov how do you setup ?

I have this error on rails c :
https://pastebin.com/CALmeDiP (too big for gitter)

tldr: uninitialized constant Int

Oskar Szrajer
@gotar
@dawidlenkiewicz splat operator | * - for arrays | ** - for hashes
Vasily Kolesnikov
@v-kolesnikov
Looks like incompatible version of dry-types. I recomend you to play with rom-mongo step by step starting from scratch (without Rails).
Oskar Szrajer
@gotar
and you can use just a construction like:
For ranges, Sequel uses a pair of inequality statements:

collection.where(horsepower: 1..5)
# SELECT * FROM ... WHERE ((horsepowert >= 1) AND (horsepower <= 5))
Vasily Kolesnikov
@v-kolesnikov
rails, active-support, bootsnap, rom3... It might be so hard...
Dawid Lenkiewicz
@dawidlenkiewicz
@gotar hmm yes but the problem I'm facing is more Sequel related I think. It works what you wrote but I'm thinking is there a good way of constructing that query when we don't know how many ranges there are (and we need to use OR between them)
Lairan
@alex-lairan
Yes I know :(
Lairan
@alex-lairan
An empty one :
Traceback (most recent call last):
    11: from main.rb:1:in `<main>'
    10: from main.rb:1:in `require'
     9: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom.rb:14:in `<top (required)>'
     8: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom.rb:14:in `require'
     7: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom/relation.rb:5:in `<top (required)>'
     6: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom/relation.rb:5:in `require'
     5: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom/relation/class_interface.rb:8:in `<top (required)>'
     4: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom/relation/class_interface.rb:8:in `require'
     3: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom/relation/curried.rb:7:in `<top (required)>'
     2: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom/relation/curried.rb:8:in `<module:ROM>'
     1: from /home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom/relation/curried.rb:9:in `<class:Relation>'
/home/necros/.rvm/gems/ruby-2.6.0/gems/rom-3.3.3/lib/rom/relation/curried.rb:17:in `<class:Curried>': uninitialized constant #<Module:0x000055ba132ea0b8>::Int (NameError)
source 'https://rubygems.org'

gem 'rom'
gem 'rom-mongo'

gem 'pry'
require "rom"
require "rom-mongo"

rom = ROM.container(:mongo, 'mongodb://localhost:27017/plezi_development')
Peter Solnica
@solnic
mongo adapter is outdated and not ready for production, I wouldn't recommend using it w/o making it up-do-date with rom 4.x and improving its implementation
Lairan
@alex-lairan
I'm a beginner user of ROM, it's easy to update the gem ? Or should I use Mongoid ?
There is not a lot of files :)
Peter Solnica
@solnic
this adapter needs a big update, I don't think it's gonna be a simple task, not to discourage you though, just being honest
Lairan
@alex-lairan

Ok, thanks @solnic

I will give up for this one, but use Dry for everything else :D

Vasily Kolesnikov
@v-kolesnikov
@solnic I have tried to upgrade rom-mongo to rom 4.x but pr's have not been reviewed. Could try again if it's needed.
Peter Solnica
@solnic
@v-kolesnikov nobody from the core team uses mongo so it's hard to keep up with this :(
I'll be working on rom again soon, I'll try to look into mongo adapter and your PR
Oskar Szrajer
@gotar
@dawidlenkiewicz not pretty but should works where{ id.in([[100,200], [500,600]].map{|x| Range.new(*x)}.map(&:to_a).flatten ) }
but for sure there is any option to join with .or
just doesn't remember how