Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 05:16
    klokare edited #503
  • Jun 29 17:40
    klokare commented #503
  • Jun 29 16:46
    klokare commented #503
  • Jun 29 16:13
    klokare opened #503
  • Jun 12 03:56
    GaikwadPratik edited #502
  • Jun 12 03:55
    GaikwadPratik opened #502
  • Jun 02 15:05

    CMogilko on v6.2.2

    (compare)

  • Jun 02 15:03

    CMogilko on master

    upgrade version golang.org/x/sy… (compare)

  • Jun 02 15:03
    CMogilko closed #501
  • Jun 01 06:29
    MehrunesSky opened #501
  • Apr 07 15:52
    GaikwadPratik closed #493
  • Apr 07 15:14
    Gerrit91 edited #500
  • Apr 07 15:09
    Gerrit91 edited #500
  • Apr 07 15:05
    Gerrit91 edited #500
  • Apr 07 15:02
    Gerrit91 edited #500
  • Apr 07 14:58
    Gerrit91 edited #500
  • Apr 07 14:52
    Gerrit91 edited #500
  • Apr 07 14:42
    Gerrit91 commented #493
  • Apr 07 13:45
    Gerrit91 edited #500
  • Apr 07 13:44
    Gerrit91 edited #500
William McGann
@tehbilly
You've got something very fun to use as training wheels! Ironically, finally at my desktop, ha.
For the sake of completeness, would you like me to put together an example of what I was talking about? A good way to stream large numbers of responses without taking forever.
William McGann
@tehbilly
func fastHandler(w http.ResponseWriter, req *http.Request) {
    res, err := r.DB("pi_baker").Table("observations").
        OrderBy(r.Desc("datetime")).
        Limit(5760).
        Pluck("datetime", "temp", "humidity").
        Run(session)

    if err != nil {
        log.Fatalln(err.Error())
    }

    w.Header().Set("Content-Type", "application/json")
    encoder := json.NewEncoder(w)
    var row map[string]interface{}

    for res.Next(&row) {
        err = encoder.Encode(row)
        if err != nil {
            // Oh no! Something bad happened!
            // Since we're not buffering the response, we aren't going to send an
            // error code and message. Maybe you can log the error and continue.
        }
    }
}
Untested in terms of performance, but to the best of my knowledge that would stream the results as individual json objects, newline delimited. So you could hack in array formatting to make it a valid json object ([,commas between each item, and ]) or make your handler consume it line-by-line.
The call to .Encode() will write each object to the http connection, not storing it in memory. Probably the best way to handle actually massive amounts of data.
William McGann
@tehbilly
The simpler way to handle it, with some memory usage and whatnot, but should show what more standard go patterns are like and would send a valid json object:
var results []map[string]interface{} = make([]map[string]interface{}, 0)
    var row map[string]interface{}

    for res.Next(&row) {
        results = append(results, row)
    }

    jsonBytes, err := json.Marshal(results)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        // Logging goes here
        return
    }

    w.Header().Set("Content-Type", "application/json")
    w.Write(jsonBytes)
Tim Shannon
@timshannon
Just curious if the dependency on the hailocab protobuf fork is intentional, or accidental. https://github.com/dancannon/gorethink/blob/master/ql2/ql2.pb.go
Daniel Cannon
@dancannon
@timshannon Ah that's accidental. My protoc I'd built against that fork. I'll push an update.
Tim Shannon
@timshannon
Thanks, I just ran into it in my local repositories, and I don't have a copy of that protobuf fork. Just wanted to check to see if it was needed or not. I now see that hailocab has some interesting forks to explore :)
Daniel Cannon
@dancannon
It's not really needed for GoRethink but it's a useful fork for proto2
Fixes some issues with enums
Lenny Händler
@algor1th
how do i call GetAll()? can anyone give me an example?
Lenny Händler
@algor1th
oh, i found it, it is called GetAllByIndex() for my needs
Daniel Cannon
@dancannon
@NoSkillDwnload glad you sorted it out, let me know if you have any further questions
NeonMonk
@NeonMonk

How would I accomplish this in GoRethink?

r.db("store").table("shelves").filter(r.row("products").contains(function(product) { return product('id').eq("122f0054-fb41-46d6-9c50-bc158ec9a2ff") }))

I've scoured the GitHub repo & docs but am none the wiser. I assume this is quite simple & I'm just missing something?

NeonMonk
@NeonMonk
Can you please confirm if this is the appropriate way to achieve this?
table := r.Table("store")
query := table.Filter(r.Row.Field("shelves").Contains(func (product r.Term) interface{} {
    return product.Field("id").Eq(product.ID)
}))
fazal
@faxal
r.DB("store").Table("shelves").Filter(r.Row("products").Contains(func (product r.Term) interface{} { return product.Field("id").Eq("122f0054-fb41-46d6-9c50-bc158ec9a2ff")}))
William McGann
@tehbilly
What's the return from the call to cursor.One()? Hard to tell from that snippet what error checking/printing is going on
Daniel Cannon
@dancannon
Hi @prophittcorey just having a look now
Hmm i wonder if the value of GeneratedKeys is correct, could you try running your code and log that value and see what is logged when your session is empty?
And just to double check, you are checking the error returned by both Run and One?
Daniel Cannon
@dancannon
Ok great thanks for checking
@prophittcorey would it be possible for you to post the entire code so I can run some more detailed tests? If you are not comfortable posting here you could maybe email it?
Great thanks
Daniel Cannon
@dancannon
@prophittcorey Ok I think I have found the cause of the issue
There seems to be an issue when you unmarshal the time into the CreatedAt term
I dont think so no
For now you can fix your code by changing the CreatedAt field to time.Time and setting it with time.Now() instead of db.Now()
Just out of curiosity why did you decide to use the rethinkdb time functions?
Yeah even though I think there is an issue with the driver not handling this properly (it should probably error since you cant convert a time back to a gorethink Term) I think using the Go time package is the best thing for you to do
No worries, let me know if you have any other questions
Daniel Cannon
@dancannon
@prophittcorey Oh just noticed you were not actually checking the error returned by One. It looks like it was actually returning an error
Daniel Cannon
@dancannon
@prophittcorey You just need err = cursor.One(&session) instead of just cursor.One(&session)
Suyash Katiyar
@skatiyar
@dancannon is current release of driver compatible with rethinkdb 2.2??
Daniel Cannon
@dancannon
@SKatiyar I have not yet update the driver to support the new features but it should be compatible . Let me know if you have any issues
Suyash Katiyar
@skatiyar
@dancannon was thinking of putting new changefeed feature in driver
Daniel Cannon
@dancannon
If you have the time I would really appreciate it.
Suyash Katiyar
@skatiyar
cool should open a issue first??
Daniel Cannon
@dancannon
Sure feel free
Suyash Katiyar
@skatiyar
and any particular point from where i can start??
Daniel Cannon
@dancannon
I will add it to the 1.2 milestone
I havnt looked into what needs to be changed yet but I imagine it will require changing the options struct for the Changes term and creating some new tests for the new response structure
Suyash Katiyar
@skatiyar
adding new option to struct, apart from that do i need to touch any other functionality??
Daniel Cannon
@dancannon
I have no idea sorry! Usually the first thing I do is look at how one of the official drivers has implemented the change
Suyash Katiyar
@skatiyar
cool, will do that. Will ask you if I run into any problems.
Daniel Cannon
@dancannon
Yeah feel free, I should be online for a while
Suyash Katiyar
@skatiyar
how can we see output while running tests??
go test -v doesn’t seem to work
fazal
@faxal
with Log or Logf
Suyash Katiyar
@skatiyar
@dancannon to add new command values do we have to get proto file from rethinkdb repo??