2017-09-14 77 views
-3

如何獲得MySQL數據庫值在節點JS JSON數組,誰能告訴我要遵循的步驟由於你是一個實現這一怎樣獲得MySQL數據庫值在JSON數組節點JS

+0

是否使用的是庫? –

+0

我是節點js的初學者。我只是想知道如何使用節點js完成此操作,請與我分享步驟,以實現 –

回答

0

初學者,這裏是你需要執行的步驟:

  1. 你需要添加一個依賴項到你的項目的MySQL(例如knex js)。
  2. 然後,您可以使用它的select()承諾訪問this gist中的行。爲了更清楚:

    return knex('books').select(knex.raw("data->'author' as author")) 
        .whereRaw("data->'author'->>'first_name'=? ",[books[0].author.first_name]) 
        .then(function(rows) { 
    
        // Here you have access to all rows as an array of objects 
        // which you can stringify 
    
        console.log("Found "+rows.length+ 
         " books with authors first_name "+ 
         books[0].author.first_name); 
    
        rows.forEach(function(row){ 
         console.log(row); 
        }); 
        }) 
    
+0

Thankyou bro ... –

+0

您可以具體告訴我我們在哪些情況下使用Web服務?我們是否使用Web服務而不是從數據庫填充網頁數據? –

+0

嗨,請爲此打開另一個問題,以避免無關討論污染此問題。如果您對答案感到滿意,請批准/註銷它。 –