Monday 10 April 2017

How to insert array of Object in to mysql with node js?

I am new to node js .I am pretty confused that how to insert array of object in to mysql with nodejs

My Code

static inserPost(postCardArray,postTitle,postedDate,username,coords){
      //postCardArray = [ {hello:'dude'} ]
        let query = "INSERT INTO ??(??,??,??,??,??,??) VALUES (?,?,?,?,?,?)";
        let inserts = ["post","post_by_username","title","post_body","posted_date","views","coords",`${username}`,`${postTitle}`,`${postCardArray}`,`${postedDate}`,0,`${coords}`];
        query = mysql.format(query,inserts);
        pool.getConnection((err,connection) => {
            if(err)
                throw err
            else
                connection.query(query,(err,rows) => {
                    connection.release();
                    console.log(rows)
                })
        })

    }

But Above Code inserts the data like this [Object] I don't know how to insert .



via Nane

No comments:

Post a Comment