DEBUG [19:56:36.550 #1] [redis] CLIENT ID
Unhandled exception: NOAUTH Authentication required. (MiniRedis::Error)
from ???
from /usr/share/crystal/src/pointer.cr:434:13 in 'receive'
from lib/mini_redis/src/mini_redis.cr:176:15 in 'send_impl'
from lib/mini_redis/src/mini_redis.cr:89:5 in '???'
from lib/onyx-http/src/onyx-http/ext/http/request/path_params.cr:1:1 in '__crystal_main'
from /usr/share/crystal/src/crystal/main.cr:47:14 in 'main'
from __libc_start_main
from _start
from ???
Onyx::EDA::Channel::Redis.new
redis.send("AUTH", password)
before, as seen at redis.io
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?
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.
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
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?
Foo(Specific)
i can emit it, then make a new Foo(All)
from that and emit it too. Not ideal but it's okay
crystal
frameworks are compiled this way