· 6 years ago · Nov 14, 2019, 10:08 PM
1'use strict'
2const sqlite = require('sqlite-async')
3
4module.exports = class Production {
5 constructor(dbName = ':memory:') {
6 return (async () => {
7 this.db = await sqlite.open(dbName)
8 let sql = 'CREATE TABLE IF NOT EXISTS "movies" ("movie" TEXT PRIMARY KEY, "Poster" LONGBLOB, "Details" TEXT);' +
9 'CREATE TABLE IF NOT EXISTS "showingSchedule"("ShowNumber" TEXT PRIMARY KEY, "date" TEXT, "time" TEXT, FOREIGN KEY("movie") REFERENCES "movies"("movie"));'+
10 'CREATE TABLE IF NOT EXISTS "movieDisplayRoom"("displayRoom" INTEGER PRIMARY KEY, "numberOfSeats" INTEGER,FOREIGN KEY ("ShowNumber") REFERENCES "showingSchedule"(ShowNumber));'
11 await this.db.run(sql)
12 return this
13 })
14 }
15 async prodDetails(movie) {
16 try {
17 let db = await this.sqlite.open(dbName);
18 sql = `SELECT * FROM movies WHERE movie = "${movie}";`;
19 const data = await this.db.get(sql);
20 await db.close();
21 let id = ''
22 await this.db.all(sql,( err, row) => {
23 if(err) console.error(err.message)
24 if(!err) id = row.id
25 return this.data;
26 }
27 catch (err) {
28 throw err
29 }
30 }