Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Davis Ford
    yessir -- forging ahead. all good. thanks!
    Davis Ford
    @jmoiron you have any idea how i can StructScan with a row having a tstzrange type? http://www.postgresql.org/docs/9.2/static/rangetypes.html
    Davis Ford
    So, is it not enough to create my own type for tstzrange and have it implement sql.Scanner interface? It seems if I use StructScan it fails to see that the type is implementing Scan and call it, so, can I not use StructScan and must fall back to Scan itself?
    Davis Ford
    I switched from NamedStatement.QueryRowx().StructScan() to NamedStatement.Get() and that is invoking the Scanner interface on said type. It looks like just StructScan does not? It seems a bit semantically where to do nstmt.Get() on an INSERT statement but it work just fine.
    Davis Ford
    @jmoiron any idea on this? jmoiron/sqlx#187
    Davis Ford
    nevermind again :)
    closed ticket
    i need to get out more :smile:
    Jason Moiron
    hehe cardboard programmer / rubber duck debugging :D
    Davis Ford
    @jmoiron, new question on embedded structs, alias and name conflicts. consider the following:
    type Foo struct { ID int }
    type Bar struct { ID int }
    type FooBar struct { Foo, Bar }`
    select foo.*, bar.* from foo join bar on foo.bar_id = bar.id
    i tried to annotate alias like:
    type Foo struct { ID int 'db:"foo" '}
    but i can't disambiguate between the two IDs even with the table alias. it seems i must use column alias on every column i'm fetching. is this the only way to disambiguate? the other option is to use row scanner, instead of StructScan. I should have mentioend, I'm trying to solve this to make StructScan work
    any body here?
    when i use GET method to get a struct data, "select * from table where id =1", if the id =1 not exits, sqlx will raise a error.
    shoud i use the error to judge the data not exits?
    What if sqlx raise a other error, how to judge?
    Sebastian Mares
    cheers guys!
    if I query two columns of a table, one that is being the ID and one that is being an arbitrary value, can sqlx map the results to a map[string]string ?
    Hi, thanks for making sqlx.
    Is there anyone here?
    Gurpartap Singh
    Hello 👋
    @Gurpartap Hey!
    I had a question about sqlx, I wonder how to handle relations with it, if it's at all possible? Many to Many relations, I want to map something into a struct.
    and by something, I mean a struct with nested slices of other structs
    Eli Saado
    I've got the same question as @johanhess1 but I was wondering if I would need relations for that
    Maybe I could just encode the structs to json and then decode them on demand
    Hi Guys!
    Asaduzzaman Pavel
    Anyone here?
    @jmoiron are you there?
    Jason Moiron
    Asaduzzaman Pavel
    I am having trouble with Named() and postgres type casting
    extract(epoch from l.time)::integer as time
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv QUERY: WITH s as (SELECT symbol from symbols)
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv          SELECT s.symbol as symbol,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  extract(epoch from l.time):? as time,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  (SELECT closing_price from tickerarchive_5minute t WHERE t.symbol = s.symbol AND time > ? AND time < ? ORDER BY time ASC LIMIT 1) AS opening_price,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  l.closing_price as closing_price,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  m.max as highest_price,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  m.min as lowest_price,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  l.volume_left as volume_left,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  l.volume_right as volume_right,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  l.market_cap as market_cap,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  l.change_1H as change_1h,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  l.change_7D as change_7d,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  l.change_1M as change_1m,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv                  l.change_1Y as change_1y
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv          FROM s,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv          lateral (SELECT * FROM tickerarchive_5minute t WHERE t.symbol = s.symbol AND time > ? AND time < ? LIMIT 1) as l,
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv          lateral (SELECT max(closing_price), min(closing_price) FROM tickerarchive_5minute t WHERE t.symbol = s.symbol AND time > ? AND time < ? as m;
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv
    ticker-archive-srv-66ffd58776-jfpxs ticker-archive-srv ARGS: []interface {}{}
    how do i escape ::integer being replaced?
    Jannik C

    Hi guys. I have a quick question:

    I have to use an already existing database and need to create some new ones.

    The old tables have sh* names in german with no consistency whatsoever.

    So for my new tables i like to use the json tag for my structs. But for the structs mapped to the old tables i need to use the db tag since the json and db tags will differ.

    How can i achieve this?

    I did already set the db.Mapper = reflectx.NewMapperFunc("json", strings.ToLower) but this overwrites the db tag (which is intended yes) but how can i only use json tags for some of the structs?
    Jannik C

    I just realized i can create a copy of the db instance and set different mappers for each one.

    So i just need to pass the different db instances to my db-access-layer.

    Still don't know how to handle joins though :-(

    Any ideas?


    Hello: good morning evenings or evenings when receiving this message,
    I would like to ask about possible strategies to prepare the status of a query with the following structure:


    The language is Goolang and the sqlx library.

    I am using a function with the following structure:

    type Translation struct {
        Translation string
    type TranslateParams struct {
        Originlanguaje string 
        Wordtotranslate string
        Targetlanguaje string 
    //TranslateWordUsingDB... TranslateWordUsingDB search one word translation in DB
    func ObtainTranslationUsingDB(validationforuse bool,originlang string, word string, targetlang string)([]Translation, error){
        translation := []Translation{}
        if validationforuse == true{
            params := TranslateParams{
                Originlanguaje  : originlang,
                Wordtotranslate : word,
                Targetlanguaje  : targetlang,
            nstmt, err := db.Conn.PrepareNamed(`select :targetlanguaje as translation from translations where :originlanguaje = :wordtotranslate`)
            if err != nil{
                return translation, err
            error := nstmt.Select(&translation, params)
            if error != nil {
                return translation, error
        return translation, nil

    But this does not work and I have not managed the methods of https://jmoiron.github.io/sqlx/#namedParams
    because they replace TABLE_COLUMN with "TABLE_COLUMN" and this does not allow the query to work.