Skip to content

Commit d7827fe

Browse files
authored
cleanup (#947)
1 parent 95e72c3 commit d7827fe

File tree

9 files changed

+3338
-62
lines changed

9 files changed

+3338
-62
lines changed

quickstarts/azure-sql/connect-and-query/README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,9 @@ Samples provided include:
7777
7878
1. In `person.js`, verify or set which configuration you want:
7979
80-
* `const config = noPasswordConfig;`
81-
* `const config = passwordConfig;`
80+
* `const database = await createDatabaseConnection(SQLAuthentication);`
81+
* `const database = await createDatabaseConnection(PasswordlessConfig);`
8282
83-
1. In `index.js`, verify or set which configuration you want:
84-
85-
* `const database = new Database(noPasswordConfig);`
86-
* `const database = new Database(passwordConfig);`
87-
88-
8983
9084
1. Start the app:
9185

quickstarts/azure-sql/connect-and-query/js/config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import * as dotenv from 'dotenv';
2-
dotenv.config({ path: `.env.${process.env.NODE_ENV}`, debug: true });
2+
3+
if(process.env.NODE_ENV === 'development') {
4+
dotenv.config({ path: `.env.${process.env.NODE_ENV}`, debug: true });
5+
}
36

47
// TIP: Port must be a number, not a string!
58
const server = process.env.AZURE_SQL_SERVER;

quickstarts/azure-sql/connect-and-query/js/database.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,33 @@ export default class Database {
9595

9696
return result.rowsAffected[0];
9797
}
98-
}
9998

100-
async function createTable() {
101-
if (process.env.NODE_ENV === 'development') {
102-
this.executeQuery(
103-
`IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Person')
104-
BEGIN
105-
CREATE TABLE Person (
106-
id int NOT NULL IDENTITY,
107-
firstName varchar(255),
108-
lastName varchar(255)
109-
);
110-
END`
111-
)
112-
.then(() => {
113-
console.log('Table created');
114-
})
115-
.catch((err) => {
116-
// Table may already exist
117-
console.error(`Error creating table: ${err}`);
118-
});
99+
async createTable() {
100+
if (process.env.NODE_ENV === 'development') {
101+
this.executeQuery(
102+
`IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Person')
103+
BEGIN
104+
CREATE TABLE Person (
105+
id int NOT NULL IDENTITY,
106+
firstName varchar(255),
107+
lastName varchar(255)
108+
);
109+
END`
110+
)
111+
.then(() => {
112+
console.log('Table created');
113+
})
114+
.catch((err) => {
115+
// Table may already exist
116+
console.error(`Error creating table: ${err}`);
117+
});
118+
}
119119
}
120120
}
121121

122122
export const createDatabaseConnection = async (passwordConfig) => {
123123
database = new Database(passwordConfig);
124124
await database.connect();
125-
await createTable();
125+
await database.createTable();
126126
return database;
127127
};

quickstarts/azure-sql/connect-and-query/js/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"scripts": {
88
"format": "prettier --write *.js",
99
"dev": "cross-env NODE_ENV=development DEBUG=express:* node index.js",
10-
"start": "node index.js",
11-
"test": "echo \"No tests yet...\"",
10+
"start": "node index.js"
1211
},
1312
"dependencies": {
1413
"express": "^4.17.21",

quickstarts/azure-sql/connect-and-query/js/person.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import express from 'express';
2-
import { passwordConfig, noPasswordConfig } from './config.js';
2+
import {
3+
passwordConfig as SQLAuthentication,
4+
noPasswordConfig as PasswordlessConfig
5+
} from './config.js';
36
import { createDatabaseConnection } from './database.js';
47

58
const router = express.Router();
69
router.use(express.json());
710

8-
const database = await createDatabaseConnection(passwordConfig);
11+
const database = await createDatabaseConnection(SQLAuthentication);
912

1013
router.get('/', async (req, res) => {
1114
try {

0 commit comments

Comments
 (0)