json
macro is used, and it seems the context.request.body
is already consumed by it before the before
callback is called. Any ideas?
context.request.body.rewind
), but I'm not sure if it would work 🤔. For some reason in current release there is no way to preserve the body... Another workaround is to copy the body in a handler (i.e. custom middleware)
rewind
is unimplemented since the body
I’m getting is a FixedLengthContent < IO::Sized
: https://github.com/crystal-lang/crystal/blob/b42631e9b3c62621f42832755427d530c6e452d2/src/http/common.cr#L37 I tried to patch HTTP::Request
like this: qszhu/http@d15c225 It works, but it feels awkward (and possibly with additional memory impact?). I’m still new to crystal, so any suggestion is welcome.
HTTP::Request
class) would indeed affect the performance. That's why I've opened onyxframework/http#77. Note that the body is read on json and form params parsing only, and it should stay unread in an endpoint if no such a parsing happened
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