File tree Expand file tree Collapse file tree 5 files changed +111
-0
lines changed
3.database-connection/service Expand file tree Collapse file tree 5 files changed +111
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ const transaction = new sql . Transaction ( /* [pool] */ )
4
+ transaction . begin ( err => {
5
+ // ... error checks
6
+
7
+ const request = new sql . Request ( transaction )
8
+ request . query ( 'insert into mytable (mycolumn) values (12345)' , ( err , result ) => {
9
+ // ... error checks
10
+
11
+ transaction . commit ( err => {
12
+ // ... error checks
13
+
14
+ console . log ( "Transaction committed." )
15
+ } )
16
+ } )
17
+ } )
18
+
19
+
20
+
21
+
22
+ //transaction
23
+ const transaction = new sql . Transaction ( /* [pool] */ )
24
+ transaction . begin ( err => {
25
+ // ... error checks
26
+
27
+ let rolledBack = false
28
+
29
+ transaction . on ( 'rollback' , aborted => {
30
+ // emited with aborted === true
31
+
32
+ rolledBack = true
33
+ } )
34
+
35
+ new sql . Request ( transaction )
36
+ . query ( 'insert into mytable (bitcolumn) values (2)' , ( err , result ) => {
37
+ // insert should fail because of invalid value
38
+
39
+ if ( err ) {
40
+ if ( ! rolledBack ) {
41
+ transaction . rollback ( err => {
42
+ // ... error checks
43
+ } )
44
+ }
45
+ } else {
46
+ transaction . commit ( err => {
47
+ // ... error checks
48
+ } )
49
+ }
50
+ } )
51
+ } )
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " 4.create-server-express" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " " ,
5
+ "main" : " server.js" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1" ,
8
+ "start" : " node server.js"
9
+ },
10
+ "author" : " " ,
11
+ "license" : " ISC" ,
12
+ "dependencies" : {
13
+ "express" : " ^4.18.2"
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ var express = require ( 'express' ) ;
2
+ var app = express ( ) ;
3
+
4
+
5
+ console . log ( '__dirname :' + __dirname ) ;
6
+ app . get ( '/index.html' , function ( req , res ) {
7
+ res . sendFile ( __dirname + "/view/" + "index.html" ) ;
8
+ } )
9
+
10
+
11
+
12
+
13
+ app . get ( '/student' , function ( req , res ) {
14
+ res . send ( 'Hello student' ) ;
15
+ } )
16
+
17
+ var server = app . listen ( 8000 , function ( ) {
18
+ var host = server . address ( ) . address
19
+ var port = server . address ( ) . port
20
+
21
+ console . log ( "Example app listening at http://%s:%s" , host , port )
22
+ } )
Original file line number Diff line number Diff line change
1
+ < html lang ="en ">
2
+ < head >
3
+ < meta charset ="UTF-8 ">
4
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Document</ title >
7
+ </ head >
8
+ < body >
9
+ < h1 > my first express project.</ h1 >
10
+
11
+ < form action = "/ " method = "GET ">
12
+ First Name: < input type = "text " name = "first_name "> < br >
13
+ Last Name: < input type = "text " name = "last_name ">
14
+ < input type = "submit " value = "Submit ">
15
+ </ form >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ {
2
+ "dependencies" : {
3
+ "msnodesqlv8" : " ^3.0.1"
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments