Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read data from DB with type Array(Int64) #31

Closed
Blacksmoke16 opened this issue Aug 30, 2018 · 2 comments
Closed

Unable to read data from DB with type Array(Int64) #31

Blacksmoke16 opened this issue Aug 30, 2018 · 2 comments

Comments

@Blacksmoke16
Copy link
Contributor

Blacksmoke16 commented Aug 30, 2018

SQL

CREATE TABLE "courier_services" (
  "id" BIGSERIAL PRIMARY KEY,
  "hubs" BIGINT[] NOT NULL,
);

Model

  class CourierService
    include Clear::Model
    self.table = "courier_services"

    with_serial_pkey
    column hubs : Array(Int64)

    def to_json
      JSON.build do |json|
        json.object do
          json.field "id", id
          json.field "hubs", hubs
        end
      end
    end
  end

Error

api2    | D, [2018-08-30 00:26:42 +00:00 #4560] DEBUG -- : [1ms] SELECT * FROM "users" WHERE (character_id = 2047918291) ORDER BY "character_id" ASC LIMIT 1
api2    | D, [2018-08-30 00:26:42 +00:00 #4560] DEBUG -- : [857µs] SELECT * FROM "courier_services" WHERE (owner_id = 2047918291) ORDER BY "id" ASC LIMIT 1
api2    | Exception: Unexpected char '_' at 1:10 (JSON::ParseException)
api2    |   from /usr/share/crystal/src/json/lexer.cr:365:7 in 'raise'
api2    |   from /usr/share/crystal/src/json/lexer.cr:361:5 in 'unexpected_char'
api2    |   from /usr/share/crystal/src/json/lexer.cr:360:38 in 'unexpected_char'
api2    |   from /usr/share/crystal/src/json/lexer.cr:245:7 in 'consume_number'
api2    |   from /usr/share/crystal/src/json/lexer.cr:63:7 in 'next_token'
api2    |   from /usr/share/crystal/src/json/parser.cr:108:11 in 'next_token'
api2    |   from /usr/share/crystal/src/json/parser.cr:113:5 in 'value_and_next_token'
api2    |   from /usr/share/crystal/src/json/parser.cr:21:7 in 'parse_value'
api2    |   from /usr/share/crystal/src/json/parser.cr:49:18 in 'parse_array'
api2    |   from /usr/share/crystal/src/json/parser.cr:33:7 in 'parse_value'
api2    |   from /usr/share/crystal/src/json/parser.cr:13:12 in 'parse'
api2    |   from /usr/share/crystal/src/json.cr:91:5 in 'parse'
api2    |   from lib/clear/src/clear/model/converter/array_converter.cr:4:1 in 'to_column'
api2    |   from src/EveToolsApi/models/courier_service.cr:3:5 in 'set'
api2    |   from src/EveToolsApi/models/courier_service.cr:3:5 in 'initialize'
api2    |   from src/EveToolsApi/models/courier_service.cr:3:5 in 'new'
api2    |   from src/EveToolsApi/models/courier_service.cr:3:5 in 'build:persisted:cache:fetch_columns'
api2    |   from lib/clear/src/clear/model/collection.cr:269:16 in 'first'
api2    |   from lib/clear/src/clear/model/collection.cr:265:5 in 'first'
api2    |   from src/EveToolsApi/models/user.cr:18:5 in 'courier_service'
api2    |   from src/EveToolsApi/routes/couriers_controller.cr:5:16 in '->'
api2    |   from lib/kemal/src/kemal/route.cr:255:3 in '->'
api2    |   from lib/kemal/src/kemal/route_handler.cr:255:3 in 'process_request'
api2    |   from lib/kemal/src/kemal/route_handler.cr:15:7 in 'call'
api2    |   from /usr/share/crystal/src/http/server/handler.cr:24:7 in 'call_next'
api2    |   from lib/kemal/src/kemal/websocket_handler.cr:13:14 in 'call'
api2    |   from /usr/share/crystal/src/http/server/handler.cr:24:7 in 'call_next'
api2    |   from lib/kemal/src/kemal/filter_handler.cr:21:7 in 'call'
api2    |   from /usr/share/crystal/src/http/server/handler.cr:24:7 in 'call_next'
api2    |   from lib/kemal/src/kemal/exception_handler.cr:8:7 in 'call'
api2    |   from /usr/share/crystal/src/http/server/handler.cr:24:7 in 'call_next'
api2    |   from lib/kemal/src/kemal/log_handler.cr:10:35 in 'call'
api2    |   from /usr/share/crystal/src/http/server/handler.cr:24:7 in 'call_next'
api2    |   from lib/kemal/src/kemal/init_handler.cr:12:7 in 'call'
api2    |   from /usr/share/crystal/src/http/server/request_processor.cr:39:11 in 'process'
api2    |   from /usr/share/crystal/src/http/server/request_processor.cr:16:3 in 'process'
api2    |   from /usr/share/crystal/src/http/server.cr:402:5 in 'handle_client'
api2    |   from /usr/share/crystal/src/http/server.cr:368:13 in '->'
api2    |   from /usr/share/crystal/src/fiber.cr:255:3 in 'run'
api2    |   from /usr/share/crystal/src/fiber.cr:29:34 in '->'
api2    |   from ???

Also tested without the to_json method, same error.

EDIT: Am using the clear master branch in my shards.yml

@Blacksmoke16
Copy link
Contributor Author

Works like a charm :) thanks.

@anykeyh
Copy link
Owner

anykeyh commented Aug 30, 2018

You're welcome,

The array support of Clear is currently quite messy, I'll figure out how to revamp it for a more robust code !

Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants