| 96 | }; |
| 97 | |
| 98 | const ensureSchema = async pool => { |
| 99 | // Wait for tables to be created (if they don't already exist). |
| 100 | await pool.request().query( |
| 101 | `IF NOT EXISTS ( |
| 102 | SELECT * FROM sysobjects WHERE name='votes' and xtype='U') |
| 103 | CREATE TABLE votes ( |
| 104 | vote_id INT NOT NULL IDENTITY, |
| 105 | time_cast DATETIME NOT NULL, |
| 106 | candidate VARCHAR(6) NOT NULL, |
| 107 | PRIMARY KEY (vote_id));` |
| 108 | ); |
| 109 | console.log("Ensured that table 'votes' exists"); |
| 110 | }; |
| 111 | |
| 112 | let pool; |
| 113 | const poolPromise = createPool() |