-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitDb.js
More file actions
44 lines (38 loc) · 981 Bytes
/
Copy pathinitDb.js
File metadata and controls
44 lines (38 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const sql = require('mssql');
const config = {
server: 'DESKTOP-9O50B9I\\SQLEXPRESS',
authentication: {
type: 'default',
options: {
userName: '', // Will use Windows auth
password: ''
}
},
options: {
trustServerCertificate: true,
encrypt: false
}
};
async function initDb() {
try {
const pool = new sql.ConnectionPool(config);
await pool.connect();
console.log('Connected to SQL Server');
// Check if devlogs database exists
const result = await pool.request()
.query("SELECT name FROM sys.databases WHERE name = 'devlogs'");
if (result.recordset.length === 0) {
console.log('Creating devlogs database...');
await pool.request()
.query('CREATE DATABASE devlogs');
console.log('Database created');
} else {
console.log('Database already exists');
}
await pool.close();
} catch (err) {
console.error('Error:', err);
process.exit(1);
}
}
initDb();