server/index.js is created to handle MySQL:
Line 1 imports
mysql for MySQL protocol.
Line 2 imports
inquirer for the intuitive immediate.
Strains 4–8 outline the person configuration.
Strains 10–12 create MySQL connection utilizing the person configuration. Line 11 allows a number of statements, which is disabled by default to keep away from potential SQL injection assaults.
Strains 14–23 outline the
question perform, which question the SQL assertion(s). If there may be an error, it’s logged on the console (line 17). In any other case, the question result’s printed (line 19). After the question, the app is prepared for the following
inquire (line 21).
Strains 25–41 outline the
inquire perform, which prompts
'mysql>'. It takes the person enter because the parameter to invoke the
question perform (line 38). If the enter is
'give up' (line 34), the connection is ended (line 36) and the app exits.
Strains 43–52 outline the
join perform, which connects to the database. If there may be an error, it’s logged on the console (line 46). In any other case, the
inquire perform is invoked (line 49).
Line 54 invokes the
Run the node app by
'node server'. It features just like
Line 3 selects the database,
Line 14 reveals all tables in
myDB , which has the
college students desk created by CLI.
Line 16 drops the
college students desk.
Line 27 reveals all tables in
myDB, which is an empty set (line 28).
Line 29 creates a desk, named
college students. This desk has columns of
title is a variable-length string with the maximal size of 255, different columns are integers.
Line 40 reveals all tables in
myDB. With the newly added
college students, it has 1 desk (line 41).
Line 42 inserts a brand new document into
Line 53 selects knowledge from
college students. The newly added document is displayed (line 54).
Line 55 quits the app.