Git Product home page Git Product logo

Comments (3)

asmyasnikov avatar asmyasnikov commented on July 23, 2024

Upstream jmoiron/sqlx works fine for structs with database/sql driver.

from ydb-go-sdk.

asmyasnikov avatar asmyasnikov commented on July 23, 2024

Query:

SELECT 
    status,
    CAST(MAX(DateTime::ToSeconds(description_time - $since) / $period) AS Int64) as interval_number,
    COUNT(1) as group_size,
    MAX_BY((status, status_mtime, short_description, description_time, state_kind, sender_node), description_time) as last_item ...
FROM %s
WHERE check_id = $check_id AND description_time >= $since AND description_time < $until
GROUP BY status, DateTime::ToSeconds(description_time - $since) / $period
ORDER BY interval_number

Parsing:

var statusStr string
var intervalNumber int64
var count uint64
var lastState struct {
    StatusStr       string
    StatusTime      time.Time
    Description     string
    DescriptionTime time.Time
    StateKindStr    string
    SenderNode      string
}

err := res.ScanWithDefaults(
    &statusStr,
    &intervalNumber,
    &count,
    db.NewTupleField(&lastState),
)

Without db.NewTupleField, need to imlement UnmarshalYDB for lastStatelike this:

func (s *lastState) UnmarshalYDB(res types.RawValue) error {
    size := res.TupleIn()
    defer res.TupleOut()
    if size != 6 {
        return errors.New(...)
    }
    res.TupleItem(0)
    s.StatusStr = res.String()
    res.TupleItem(1)
    s.StatusTime = res.Timestamp()
    res.TupleItem(2)
    s.Description = res.String()
    res.TupleItem(3)
    s.DescriptionTime = res.Timestamp()
    res.TupleItem(4)
    s.StateKindStr = res.String()
    res.TupleItem(5)
    s.SenderNode = res.String()
    return nil
}

from ydb-go-sdk.

asmyasnikov avatar asmyasnikov commented on July 23, 2024

Duplicate of #1076

from ydb-go-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.