File tree Expand file tree Collapse file tree 9 files changed +3338
-62
lines changed
quickstarts/azure-sql/connect-and-query Expand file tree Collapse file tree 9 files changed +3338
-62
lines changed Original file line number Diff line number Diff line change @@ -77,15 +77,9 @@ Samples provided include:
7777
78781. 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
90841. Start the app:
9185
Original file line number Diff line number Diff line change 11import * 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!
58const server = process . env . AZURE_SQL_SERVER ;
Original file line number Diff line number Diff 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
122122export const createDatabaseConnection = async ( passwordConfig ) => {
123123 database = new Database ( passwordConfig ) ;
124124 await database . connect ( ) ;
125- await createTable ( ) ;
125+ await database . createTable ( ) ;
126126 return database ;
127127} ;
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 11import express from 'express' ;
2- import { passwordConfig , noPasswordConfig } from './config.js' ;
2+ import {
3+ passwordConfig as SQLAuthentication ,
4+ noPasswordConfig as PasswordlessConfig
5+ } from './config.js' ;
36import { createDatabaseConnection } from './database.js' ;
47
58const router = express . Router ( ) ;
69router . use ( express . json ( ) ) ;
710
8- const database = await createDatabaseConnection ( passwordConfig ) ;
11+ const database = await createDatabaseConnection ( SQLAuthentication ) ;
912
1013router . get ( '/' , async ( req , res ) => {
1114 try {
You can’t perform that action at this time.
0 commit comments