Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    AlexGravenSparkfly
    @AlexGravenSparkfly
    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                     |           |          |
    .SetKeys works, but I'd like the tag much more :/
    DB is a postgres.
    Osram-Gru
    @Osram-Gru
    I import gorp "gopkg.in/gorp.v1"
    Osram-Gru
    @Osram-Gru
    ... and it works with v2. Is that mentioned in https://github.com/go-gorp/gorp ?
    Osram-Gru
    @Osram-Gru
    Uh, December 2018 ... seems to be a very active project ;)
    Samuel Nelson
    @nelsam
    ugh, mornings
    alright, so the docs and the readme were updated in master when that feature was added
    which means that if you're looking at the docs or the readme from the v1 version, they won't have that feature
    you have to be looking at master or v2 to see the docs about it
    also, per activity of the project: I merge PRs and I try to keep it caught up with the world, but the other maintainers dropped off the radar and I don't use SQL in my job any more
    so I kind of consider gorp to be a project that is "done" for the most part
    hinet
    @hinet
    I want to ignore a field, but I need to join to query the field. What should I do?
    because this only saves the ID in another table in this table, I need the join query name, so the field representing the ID associated name in the structure is ignored.
    hinet
    @hinet
    type Article struct {
        Id         int64 `db:"id, primarykey, autoincrement"`
        Title      string
        CategoryName   string `db:"-" json:"category_name"`
        CategoryId int64  `db:"category_id" json:"category_id"`
    }
    type Category struct{
        Id         int64 `db:"id, primarykey, autoincrement"`
        Name string
    }
    var list []Article
    _,err := Dbm.Select(&list,"select a.*,c.name CategoryName from Article a,Category c where a.category_id = c.id"
    //Query result CategoryName is empty.
    can you help me?
    Samuel Nelson
    @nelsam
    there's a fork of gorp from a while back that might still be in use that solves for this case, but current gorp does not
    can you create an issue on github?
    I don't have a lot of time to spend on gorp, but I can look in to it
    This message was deleted
    Samuel Nelson
    @nelsam
    for now, try falling back to standard sql.Rows logic. something like the following should work:
    type Article struct {
         ID         int64 `db:"id, primarykey, autoincrement"` // ID, not Id; read Effective Go for reasoning
        Title      string
        CategoryID `db:"category_id" json:"-"`
        Category Category `db:"-" json:"category"`
    }
    
    type Category struct{
        ID         int64 `db:"id, primarykey, autoincrement"`
        Name string
    }
    
    // Note: *never* use 'select *' in code.  It makes your code less forward-compatible, which causes
    // a huge mess of issues when you start needing to do rolling deploys.  Among other things.
    rows, err := Dbm.Query("SELECT a.id, a.title, a.category_id, c.id, c.name FROM Article AS a INNER JOIN Category AS c ON a.category_id = c.id")
    if err != nil {
        // handle err
    }
    for rows.Next() {
        var (
            article Article
            cat Category
        )
        rows.Scan(&a.ID, &a.Title, &a.CategoryID, &c.ID, &c.Name)
        // do what you need to with the article and category
    }
    if err := rows.Err(); err != nil {
        // handle err
    }
    hinet
    @hinet
    thanks
    xed
    @xed
    Hi, I try to use sql-migrate for oracle DB(through gorp), and I don`t undestand what I need insert in datasource (dsn connections string), how it looks for oracle?
    Samuel Nelson
    @nelsam
    I have no idea, tbh; but if you're using oracle, you should have some priority support, right?
    they should be able to help you
    Nikesh Pathak
    @nikeshpathak
    Hi , I am trying to create table if not exist using gorp. But it's generating wrong query for Oracle db. Could you please suggest on this
    Samuel Nelson
    @nelsam
    what query is being generated, and what should it be generating?
    you'll probably need to make a PR to update the oracle dialect, here: https://github.com/go-gorp/gorp/blob/master/dialect_oracle.go
    12dollar
    @12dollar
    Hi. Let‘s put a 2021 message here which most probably already answers my question. I have a project based on gorp which I‘m going to pick up again and create a business application out of it. I‘d like an honest opinion if you deem gorp still future-proof or if I should invest some more effort into removing the implementation
    Samuel Nelson
    @nelsam
    I believe that gorp should continue to work for applications which need it, but I think the API is too rigid for long-term maintenance to be viable. previous maintainers and I have tried to come up with a backward-compatibility-breaking design that would be easier to maintain, but the fact is that most of the time, databases are too different for a generic ORM to be useful long-term. I think gorp is fine for getting projects off the ground, but I haven't seen any use case where a generic ORM stays in place past the MVP.
    in my current work, I'm using a code generator to generate queries from migration files, relying on indexed columns to decide which query functions should be generated