Node.js Synchronous queries with MySQL

前端 未结 6 2000
走了就别回头了
走了就别回头了 2021-01-01 23:23

I\'m working on creating a user registration system for a website that I am working on but I am running into a few issues.

I\'m trying to stay away from having to ne

6条回答
  •  情歌与酒
    2021-01-01 23:48

    You could simply use a module for node that provide synchronous functions. Here you'll find a module that provide sync/async functions to deal with mysql.

    https://github.com/Will-I4M/node-mysql-libmysqlclient

    Here is how you could use it in order to execute a synchronous query :

    var config = require("./config.json") ;
    var mysql = require('mysql-libmysqlclient') ;
    var client = mysql.createConnectionSync(config.host, config.user, config.password, config.database) ;
    
    var query = "SELECT * FROM Users ;" ;
    var handle = client.querySync(query) ;
    var results = handle.fetchAllSync() ;
    
    console.log(JSON.stringify(results)) ; 
    

提交回复
热议问题