AtnNn / librethinkdbxx

RethinkDB driver for C++
Other
98 stars 31 forks source link

Insert, Update & Delete #13

Closed kamlesh-nb closed 8 years ago

kamlesh-nb commented 8 years ago

Is it possible to perform Insert, Update & Delete operations on the tables. I have tried querying the tables and it works fine, but Insert never worked. Could you please help.

AtnNn commented 8 years ago

It should be possible. What have you tried? How did it not work?

kamlesh-nb commented 8 years ago

I have tried below code..

include

include

include

namespace R = RethinkDB;

int main() { string json; // assigned some json string to it std::unique_ptr conn = R::connect("localhost", 28015); R::table("poll").insert(json).run(*conn);

}

Hope the code is correct. It always throws exception, RethinkDB Error. Could you please help with the sample code for insert, update and delete.

neonrust commented 8 years ago

That seems to be missing a database reference.

Not sure of the syntax but it could be something like this:

R::db("the_database").table(...  The rest of the statement

Alternative, it might be possible to set the current db using use().

kamlesh-nb commented 8 years ago

Yes, I used database reference also, but it failed.

neonrust commented 8 years ago

Please update the code, and some more information would be useful, e.g. the contents of the "json" setting and foremost; what does the error say?

neonrust commented 8 years ago

I don't know much at all about this driver, but is string actually the correct type to use as insert value? Shouldn't it be some kind of mapping object?

AtnNn commented 8 years ago

@kamlesh-bambarde insert takes as an argument an object or an array of objects, not a string.

This might work:

R::table("poll").insert(R::json(json)).run(*conn);