GenieFramework / SearchLight.jl

ORM layer for Genie.jl, the highly productive Julia web framework
https://genieframework.com
MIT License
139 stars 16 forks source link

ERROR: MethodError: Cannot `convert` an object of type Vector{SQLInput} to an object of type SQLInput #66

Closed deahhh closed 10 months ago

deahhh commented 1 year ago

ENV:

(Ehl) pkg> status
Project Ehl v0.1.0
Status `~/Videos/ehl/Project.toml`
  [c43c736e] Genie v5.15.0
  [e115e502] GenieAuthentication v2.2.0
  [af3f74f6] GenieAuthorisation v2.0.1
  [6d011eab] Inflector v1.0.1
  [5134c85a] LSHFunctions v0.2.0
  [194296ae] LibPQ v1.15.1
  [340e8cb6] SearchLight v2.10.0
  [4327cdd6] SearchLightPostgreSQL v2.3.3
  [ade2ca70] Dates
  [56ddb016] Logging

I've debugged: by replaced model_types.jl#119 SQLInput(a::Vector{T}) where {T} = SQLInput.(a) with SQLInput(a::Vector{T}) where {T} = SQLInput("{"*join(SQLInput.(a), ",")*"}")

please check model_types.jl#140 convert(::Type{SQLInput}, r::Real) = SQLInput(parse(r))

too.

essenciary commented 1 year ago

Thanks - what's the code that generates this error?

deahhh commented 1 year ago

Thanks - what's the code that generates this error?

model:

module Articles

import SearchLight: AbstractModel, DbId, save!
import Base: @kwdef, convert

export Article

@kwdef mutable struct Article <: AbstractModel
  id::DbId = DbId()
  kw::Vector{String} = []
end

Base.convert(::Type{Vector{String}}, v::String) = 
  map(x->x.captures[1]|>String, eachmatch(r"E'(.*?)'", v))
end

migration:

module CreateTableArticles

import SearchLight.Migrations: create_table, column, columns, pk, add_index, drop_table, add_indices

function up()
  create_table(:articles) do
    [
      pk()
      column(:kw, :string, "[]", limit=16)
    ]
  end

end

function down()
  drop_table(:articles)
end

end

test code:

using Ehl.Articles
using Ehl.Articles:*
Article(kw=["hello"]) |> save!
Article(kw=["good", "bye"]) |> save!
deahhh commented 1 year ago

Thanks! Could you teach me how to store tsvector typed value? And how to store json type? As they are not in the dictionary named TYPE_MAPPINGS in file SearchLightPostgreSQL.jl .