Tuesday, June 13, 2017

How do you get id of a record newly inserted into the database with only one query .

In my project I was inserting a project into a database and I need to assign the "id" created when project is inserted into database.

r.db("DatabaseName").table("TableName").insert("Values")


{
"deleted": 0 ,
"errors": 0 ,
"generated_keys": [
"6538d988-f8e8-4ab0-bf71-f363fce91b9f"
] ,
"inserted": 1 ,
"replaced": 0 ,
"skipped": 0 ,
"unchanged": 0

}



The query to insert will provide a response as shown above and we can make use of the generated_keys to use for our purpose.

The database used is rethinkdb and query is written in reql language.



No comments:

Post a Comment

Call a function in child component from parent component in React

Consider the following parent component class Parent extends React.Component { constructor(props) { super(props);         thi...