biokoda / actordb

ActorDB distributed SQL database
Mozilla Public License 2.0
1.9k stars 71 forks source link

basic example using thrift + go #20

Closed atomi closed 8 years ago

atomi commented 8 years ago

I'm learning all about thrift and actordb and I'm trying to get a basic INSERT going. Here is the golang code I have

package main

import (
    "atomi/go-actordb/actordb" // gen-go
    "fmt"
    "net"
    "os"

    "git.apache.org/thrift.git/lib/go/thrift"
)

// Transport: Not-framed TCP
// Protocol: Binary
func main() {
    var protocolFactory thrift.TProtocolFactory
    protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()

    var transportFactory thrift.TTransportFactory
    transportFactory = thrift.NewTTransportFactory()

    var transport thrift.TTransport
    var err error
    transport, err = thrift.NewTSocket(net.JoinHostPort("127.0.0.1", "33306"))

    if err != nil {
        fmt.Fprintf(os.Stderr, "NewTSocket: %s\n", err)
        os.Exit(1)
    }

    transport = transportFactory.GetTransport(transport)

    if err = transport.Open(); err != nil {
        fmt.Fprintf(os.Stderr, "transport.Open(): %s\n", err)
        os.Exit(1)
    }

    var clientFactory *actordb.ActordbClient
    clientFactory = actordb.NewActordbClientFactory(transport, protocolFactory)

    temp, err := clientFactory.Login("myuser", "mypass")
    if err != nil {
        fmt.Fprintf(os.Stderr, "clientFactor.Login: %s\n", err)
        os.Exit(1)
    }
    defer transport.Close()
    r1, e1 := clientFactory.ExecSql("INSERT INTO asdf (txt) Values ('rwrinf')")
    fmt.Println("clientFactory.ExecSql():", r1, e1)
    fmt.Printf("%v\n", temp.GetSuccess())

}

I can login and connect to a single running actordb but it fails on clientFactory.ExecSql <nil> InvalidRequestException({Code:Error Info:})

I'm hoping to test multiple connections and multiple instances I couldn't find any documentation on thrift/actordb specific api (I've just been going off the generated code) any advice would be appreciated. I can help with a blog post or two about my experience for others interested. Thanks.

SergejJurecko commented 8 years ago

ExecSql requires you to use "actor mytype(myactor) create; INSERT INTO ...."

We recommend using the ExecSingle/ExecSingleParam calls. This way you can specify the actor using parameters. I'm not a go programmer but it should look like this:

var flags [1]string
flags[0] = "create"
ExecSingle("myactor","mytype", "INSERT INTO...",flags)

Calls are documented in the thrift file: https://github.com/biokoda/actordb/blob/master/adbt.thrift

atomi commented 8 years ago

WFM. Thanks.