Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Sep 20 08:32
    vladfaust transferred #85
  • Sep 20 08:32
    watzon opened #25
  • Sep 19 23:51
    watzon opened #85
  • Aug 25 17:33
    t-richards opened #84
  • Aug 13 11:21
    vladfaust closed #7
  • Aug 13 11:19
    vladfaust closed #108
  • Aug 13 11:19
    vladfaust closed #109
  • Aug 13 11:17
    vladfaust closed #24
  • Aug 09 08:46
    vladfaust review_requested #109
  • Aug 09 08:46
    vladfaust review_requested #7
  • Aug 08 20:13
    arubinofaux opened #7
  • Aug 08 20:13
    arubinofaux opened #109
  • Aug 02 11:31
    RemiKalbe edited #24
  • Aug 02 11:29
    RemiKalbe opened #24
  • Aug 01 12:52
    RemiKalbe edited #83
  • Aug 01 12:51
    RemiKalbe opened #83
  • Jul 30 18:36
    vladfaust closed #23
  • Jul 30 18:33
    vladfaust transferred #82
  • Jul 30 18:33
    RemiKalbe opened #23
  • Jul 30 15:55
    RemiKalbe opened #82
Vlad Faust
@vladfaust
You could create an issue @ mini_redis if you think this should be automated
Dainel Vera
@arubinofaux_twitter
@vladfaust thanks for the reply, it makes a lot more sense to me now
Qinsi (James) ZHU
@qszhu
Is there a way to use aggregate functions with the SQL builder? Currently I’m using the raw SQL like Onyx::SQL.scalar(“select avg(score) from scores where …”).
Vlad Faust
@vladfaust
That's the perfect way. Query builder is designed to be minimal, with very common things only
Qinsi (James) ZHU
@qszhu
I see. Thanks!
Vlad Faust
@vladfaust
Also, you could do that: Onyx::SQL.scalar(User.where(a: b).select("avg(score)"))
As most of query builder methods support raw SQL
Qinsi (James) ZHU
@qszhu
Nice! Wasn't aware of that
Vlad Faust
@vladfaust
The real reason for Query builder existence is that I didn't want to type full table names in SQL queries =) And also converting SQL rows to Crystal. That's minimal
I never intended to replace SQL. You should know raw SQL to make it work better, anyway
Qinsi (James) ZHU
@qszhu
Just enough to solve my problem👍
Vlad Faust
@vladfaust
That's another Onyx's motto =)
Qinsi (James) ZHU
@qszhu

I’m trying to return all the fields of a reference with join according to the doc: https://docs.onyxframework.org/sql/query.html#join Say I want to get all the fields of author. Do I have to write raw sql like

  .join(author: true) do |x|
    x.select(“author.*”)
  end

or is there any other way?

Vlad Faust
@vladfaust
Onyx::SQL is broken on 0.29.0. See onyxframework/sql#106. Any help would be appreciated
Vlad Faust
@vladfaust
Everything's fine, gonna update to 0.29.0 tomorrow :tada:

Hey @qszhu, sorry for the late response. You can do this:

.join(author: true, &.select(User))

This would effectively select all the fields of the author with proper table naming author. instead of users.

Qinsi (James) ZHU
@qszhu
I see. Now that makes sense. Thanks!
Mia Iversen
@chillfox

I am not really getting how to make this work.
(first time I am trying to use a database instead of flat files)

what I would like to do is:

p headings[0].book.title

The code...
(sqlite)

CREATE TABLE book (
  book         INTEGER      PRIMARY KEY,
  title           TEXT              NOT NULL
);

CREATE TABLE heading (
  heading  INTEGER  PRIMARY KEY,
  title      TEXT     NOT NULL,
  page     INTEGER  NOT NULL,
  book     INTEGER  NOT NULL,
  FOREIGN KEY (book) REFERENCES book(book)
);
class Models::Book
  include Onyx::SQL::Model

  schema book do
    pkey book : Int64
    type title : String, not_null: true
  end
end

class Models::Heading
  include Onyx::SQL::Model

  schema heading do
    pkey heading : Int64
    type title : String, not_null: true
    type page : Int32, not_null: true
    type book : Book, not_null: true, key: "book"
  end
end


headings = Onyx::SQL.query(Models::Heading.join(book: true, &.select(Models::Book)))
pp headings
Mia Iversen
@chillfox

The error I get when trying the above

Error in src/mini_index.cr:73: no overload matches 'Models::Heading.join', book: Bool
Overloads are:
 - Onyx::SQL::Model::ClassQueryShortcuts(T)#join(table : String, on : String, as _as : String | ::Nil = nil, type : Onyx::SQL::Query::JoinType = :inner)
 - Onyx::SQL::Model::ClassQueryShortcuts(T)#join(reference : T::Reference, on : String | ::Nil = nil, as _as : String = reference.to_s.underscore, type : Onyx::SQL::Query::JoinType = :inner)
 - Onyx::SQL::Model::ClassQueryShortcuts(T)#join(reference : T::Reference, klass, *, on : String | ::Nil = nil, as _as : String = reference.to_s.underscore, type : JoinType = :inner, &block)

  headings = Onyx::SQL.query(Models::Heading.join(book: true, &.select(Models::Book)))

I can work around it like this

headings = Onyx::SQL.query(Models::Heading.all)
books = Onyx::SQL.query(Models::Book.all)

pp books.select {|b| b.book == headings[0].book.try(&.book)} .first.title

Does anyone have any idea of what I am doing wrong?

Cristian Șerb
@cserb
This message was deleted
Marwan Rabbâa
@waghanza
Hi, has anyone create a static binary of an onyx app ?
Daniel Worrall
@Daniel-Worrall
Can I use EDA https://github.com/onyxframework/eda to emit a generic Event so I can handle events from "all" events?
Vlad Faust
@vladfaust
Sorry, I don't understand the question
Daniel Worrall
@Daniel-Worrall
I was looking to subscribe a handler to a generic class like Foo(T) but I worked around it by subscribing it on Foo(All) where all is a union alias
Then when I have Foo(Specific) i can emit it, then make a new Foo(All) from that and emit it too. Not ideal but it's okay