尝试从Sqlite3中的一对多关系获取json数据

时间:2019-03-17 16:23:37

标签: javascript sql node.js sqlite

我试图从我创建的数据库中获取一对多数据,但是得到的是一个空数组,当我在sqlite3终端上键入命令时,该表正在显示,但是当我从node.js,它是一个空数组。

这是命令

FROME employee as employee inner join departement as Departement
on employee.dept_id = departement.id where employee.dept_id = 3```

It shows the table, and when I call the following from node.js 

db.all(thatQuery, (err, rows) => {
   if(err) console.log(err)
   console.log(rows) // what I get is empty array []
})


//here is my create table :



const departement = `CREATE TABLE IF NOT EXISTS departement(
                      id INTEGER PRIMARY KEY AUTOINCREMENT,
                      dept_name TEXT NOT NULL,
                      city TEXT
                      )`;

  const employee = `CREATE TABLE IF NOT EXISTS employee(
                    id INTEGER PRIMARY KEY AUTOINCREMENT,
                    firstName TEXT NOT NULL,
                    lastName TEXT,
                    gender TEXT NOT NULL CHECK (gender IN ('Male', 'Female')),
                    email TEXT NOT NULL UNIQUE ,
                    phone TEXT,
                    dept_id INTEGER,
                    FOREIGN KEY (dept_id) REFERENCES departement(id) ON UPDATE CASCADE ON DELETE CASCADE
                    )

Doesn't node-sqlite3 support to get query relationship?? 

I want the result which is json of the data;

0 个答案:

没有答案