Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Kaleb Elwert
    @belak
    Fair enough
    Russell Haering
    @russellhaering
    Does gorp provide any mechanism for mapping a sql.Row to a struct?
    I'm trying to use a prepared statement to optimize a gorp Get, but its turning into a little bit of a rabbit hole; gorp has no way to actually execute a sql.Stmt, so I'm doing it manually and now trying to figure out how to map the resulting row back onto the struct. Not sure if there is a better way.
    Samuel Nelson
    @nelsam
    You might need to make a PR for that, but I'm out at dinner, so I can't double-check. I'd accept a PR with tests if you do, though.
    I think the code is probably already there, just not exported
    Russell Haering
    @russellhaering
    OK, I'll do some digging around, I'll submit a PR if an upstream change ends up making the most sense. We've got a little bit of wrapper code that integrates squirrel and DbMap to generate squirrel queries for gorp tables, so I might be able to just do this as some kind of extension there
    Either way, I appreciate the quick response, this is definitely not needs-a-response-from dinner urgent though
    Samuel Nelson
    @nelsam
    Eh, service is slow, I have a nice cream ale; I don't mind taking a minute :)
    JustDoingThisForGitter
    @JustGitter_twitter
    Is there any documentation on how to set this thing up?
    I'm seeing errors in retrieving records, nothing works.
    "could not read string at (hex address) due to protocol error E80" when I look at the returned value within the function that gets it, it's NIL when I return from that function."
    Samuel Nelson
    @nelsam
    most of our setup docs are in our readme right now; what database are you using, and what code is causing the failure?
    AlexGravenSparkfly
    @AlexGravenSparkfly
    Why does "Like" not work in GORP?
    Is there any way to make this work?
    My query is something like this:
    SELECT * FROM items WHERE account_id = $1 AND lower(name) LIKE '%$2%'
    I provide $1 and $2 but it gives me the error
    pq: got 2 parameters but the statement requires 1
    I know if I change that to = $2 it works
    no complaints about "got 2 parameters, requires 1"
    I've tried escaping this multiple ways, but it doesn't work. How are you supposed to use "Like" statements?
    Thanks in advance.
    AlexGravenSparkfly
    @AlexGravenSparkfly
    If I go completely around this and build the string manually, it completely works, but that's VERY prone to SQL injection.
    Samuel Nelson
    @nelsam
    like $2 will work, you just need to add the '%' characters to the string
    also, i really hope you're not actually doing SELECT * in your code
    AlexGravenSparkfly
    @AlexGravenSparkfly
    doesnt
    sorry
    I tried it hence asking here
    (sorry was typing with one hand as was on phone to boss :)
    The query has been slightly changed so as to preserve company IP
    but the point is ONE or the OTHER will work
    where account_id = $1
    OR
    where name like $2 where $2 is "'%" + foo + "%'"
    But I need BOTH to work because I need to do the above query
    How do I do the above query in GORP where it will work?
    That same query done directly to Postgres gives results
    whereas with Gorp it does not
    Samuel Nelson
    @nelsam
    what I said, but you don't use the quotes in $2
    AlexGravenSparkfly
    @AlexGravenSparkfly
    Oh hold on, so where $2 is "%" + foo + "%"
    let me try that
    Samuel Nelson
    @nelsam
    yep, that one should work
    AlexGravenSparkfly
    @AlexGravenSparkfly
    Oh, that's perfect!
    Thanks!
    Let me find the docs and try and add that to them... I'm sure that'll help someone down the road.
    Thanks for your quick and frankly really awesome reply.
    Samuel Nelson
    @nelsam
    no problem :)
    little more technical detail: when postgres does the variable binding, it will figure out the correct type for the value; when it realizes the value is a string, it will effectively add the quotes for you
    so having the quotes around it made postgres bind that as if you were doing like '\'%foo%\''
    Osram-Gru
    @Osram-Gru

    Hi, I'm having problems with the primarykey tag in gorp. It seems to be ignored resep. used as column name !?

    type Meta struct {
        Periodic
        Id        string    `db:"uuid, primarykey"`
        CreatedAt time.Time `db:"createdAt"`
    }

    That ends up in the database as:

     \d gtin
                                 Table "public.gtin"
          Column      |           Type           | Collation | Nullable | Default 
    ------------------+--------------------------+-----------+----------+---------
     uuid, primarykey | text                     |           |          |