The database is downloaded and installed by Google.

From the NodeJS course at Coderwhy.

Terminal Connection to database

If we want to operate data, we need to establish a connection with the data first, the most direct way is through the terminal to connect;

The difference between the two methods is whether to enter a password directly or in ciphertext on another line.

  • Mysql -uroot -p Password
  • mysql -uroot -p. Press Enter and enter your password.

MySQL is the default database

  • Infomation_schema: Information database, including other databases, tables, columns, and access permissions maintained by MySQL.
  • Performance_schema: a performance database that records resource consumption information during the running of the MySQL Server database engine.
  • Mysql: used to store user information, permission information and some log information of the database manager.
  • Sys: it’s like a simple performance_schema that aggregates data from a performance database into a form that’s easier to understand;

GUI Tool selection

I recommend Navicat Premium. Because… He charges fees. If you want free, find your own resources. Download address www.navicat.com/en/products…

Understanding SQL statements

If we want to manipulate a database (especially in a program), we need a language to communicate with the database. This language is SQL:

  • SQL is Structured Query Language, called Structured Query Language, or SQL for short.
  • Statements written in SQL are called SQL statements;
  • SQL statements can be used to operate on a database;

In fact, the common relational database SQL statements are relatively similar, so you learn MySQL SQL statements, such as Oracle or other relational databases, is very convenient.

Common specifications for SQL statements:

  • Keywords are usually capitalized, such as CREATE, TABLE, SHOW, and so on.
  • At the end of a statement, the;At the end
  • If you encounter keywords as table names or field names, you can use ‘ ‘packages;

Classification of SQL statements

  • Data Definition Language (DDL) : Data Definition Language. You can use DDL statements to create, delete, and modify databases or tables.
  • Data Manipulation Language (DML) : Data Manipulation Language. You can add, delete, and modify tables using DML statements.
  • Data Query Language (DQL) : Data Query Language. Records can be queried from the database using DQL. (key)
  • Data Control Language (DCL) : Data Control Language. Perform related access control operations on database and form permissions;

The data type of SQL

We know that different data is divided into different data types, and the same is true in a database.

MySQL supports the following data types: number type, date and time type, string (character and byte) type, space type, and JSON data type

  • Numeric types
    • INTEGER Number types: INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT.
    • Floating-point number types: FLOAT, DOUBLE (FLOAT is 4 bytes, DOUBLE is 8 bytes).
    • Exact NUMERIC types: DECIMAL, NUMERIC (DECIMAL is the implementation of NUMERIC). The DECIMAL() method takes two arguments, one for the number of digits and two for the number of decimals.
  • The date type
    • YEAR types toYYYYFormat displays values. Supported ranges 1901 to 2155, and 0000.
    • The DATE type is used for values with a DATE part but no time part in the formatType - DD YYYY - MM. The supported range is ‘1000-01-01’ to ‘9999-12-31’.
    • The DATETIME type is used to contain the date and time portion of a value in the formatYYYY-MM-DD hh:mm:ss. The value ranges from ‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’.
    • The TIMESTAMP data type is used to contain both the date and time parts of the value in the formatYYYY-MM-DD hh:mm:ss. The range is the UTC time range: ‘1970-01-01 00:00:01’ to ‘2038-01-19 03:14:07’;

Also: DATETIME or TIMESTAMP values can be included in up to microsecond (6 bits) precision after the fractional second part. The DATETIME value can range from ‘1000-01-01 00:00:00.000000’ to ‘9999-12-31 23:59:59.999999’.

  • String type
    • The CHAR type is of a fixed length when the table is created, and can be any value between 0 and 255. When queried, trailing Spaces are removed.
    • A value of type VARCHAR is a variable length string whose length can be specified from 0 to 65535. Trailing Spaces are not removed when queried.
    • The BINARY and VARBINARY types are used to store BINARY strings, which are byte strings.
    • Blobs are used to store large binary types.
    • TEXT is used to store large string types. If the VARCHAR still cannot be stored, the TEXT type will be used.

Table constraints

In order to distinguish the uniqueness of each record in a table, there must be one field that is never repeated and never empty. This field is usually set as the PRIMARY KEY.

  • The primary key is the only index in the table.
  • It must be NOT NULL. If NOT NULL is set, MySQL implicitly sets it to NOT NULL.
  • A PRIMARY KEY(key_part,…) can also be a multi-column index. We commonly call this the union primary key.
  • Suggestion: The primary key fields in development should be business independent. Try not to use business fields as primary keys.

We can use UNIQUE to constrain certain fields in development that we want to be UNIQUE and not duplicate, such as mobile phone number, ID number, etc.

  • Fields using the UNIQUE constraint must be different in the table;
  • For all engines, the UNIQUE index allows NULL to contain columns with multiple NULL values. That is, records of the same field can both be NULL.

We can use NOT NULL to constrain certain fields where we require the user to insert values that cannot be NULL.

For certain fields we want to give a DEFAULT value when no value is set. We can use DEFAULT to do this.

AUTO_INCREMENT Certain fields, such as the user ID, can be incremented without setting the value, using AUTO_INCREMENT.

FOREIGN KEY REFERENCES External (External primary KEY) (FOREIGN KEY). Some fields want to reference fields in other tables as values. Join the two tables together.

Database operations

Operations are performed on the database through DDL statements

  • Look at all the data
    SHOW DATABASES;
Copy the code
  • Use a certain data
USE database name;Copy the code
  • View the database currently in use
    SELECT DATABASE();
Copy the code
  • Creating a database
    CREATE DATABASE IF NOT EXISTSDatabase nameDEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; //These are the default encodings for the database. Utf8mb4_0900_ai_ci Specifies the collation of data in the database. Indicates that the light and heavy tone and case are not sensitive.Copy the code
  • Deleting a Database
    DROPDATABASE IF EXIT 'DATABASE name';Copy the code
  • Modifying a Database
Alter database character set and collation rulesALTERDATABASE 'The name of the DATABASECHARACTER SET = utf8 COLLATE = utf8_unicode_ci;
Copy the code

Data table operations

Manipulate tables through DDL statements

  • View all data tables
    SHOW TABLES;
Copy the code
  • View a table structure
    DESC` table name `;Copy the code
  • Create a table

DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP When we insert data, the current time is automatically added to this field.

    CREATE TABLE IF NOT EXISTS'table name' (# field type constraint IDINT PRIMARY KEY AUTO_INCREMENT,
        name VARCHAR(20) NOT NULL,
        age INT DEFAULT 0,
        telPhone VARCHAR(20) DEFAULT ' ' UNIQUE NOT NULL
    );
Copy the code
  • Delete table
    DROP TABLE IF EXISTS` table name `;Copy the code
  • Modify the table

Make changes to table structures, fields, etc. Do not modify the data content.

    # 1.Modify the name of the tableALTER TABLE'RENAME the original table nameTO'modify table name'; #2.Add a new columnALTER TABLE` ` table nameADD'field' field type;ALTER TABLE `moment` ADD `updateTime` DATETIME;
    # 3.Delete a column of dataALTER TABLE` ` table nameDROP` ` field; #4.Change the name of the columnALTER TABLE'table name' CHANGE 'original field' 'modified field' changed field type; #5.Modify the data type of the columnALTER TABLE'table name' MODIFY 'field' field type; #6.Create another table based on the table structure (without copying data)CREATE TABLE IF NOT EXISTS` ` table nameLIKE'refer to table name' #7.Create another table based on the table structure (and copy the data)CREATE TABLE IF NOT EXISTS` ` table nameAS (SELECT * FROM'table name');Copy the code

DML statements are used to manipulate tables, such as inserting data, deleting data, and modifying data

  • Insert data into a table
Insert data in the order of the fields in the tableINSERT INTO` ` table nameVALUES(the value inserted by the corresponding field); Insert data into the specified fieldINSERT INTO'table name' (several fields)VALUES(the value inserted by the corresponding field);INSERT INTO `products` (`title`, `description`, `price`, `publishTime`) 
    VALUES ('iPhone'.'iPhone12 as long as 998'.998.88.'2020-10-10');
Copy the code
  • Delete data from a table
Drop all data in tableDELETE FROM` table name `; # delete the data that meets the criteriaDELETE FROM` ` table nameWHEREConditions;DELETE FROM `products` WHERE `title` = 'iPhone';
Copy the code
  • Modify the data in the table

Modify the data content.

UPDATE 'table name'SETModified content; UPDATE `products`SET `title` = 'iPhone12', `price` = 1299.88; UPDATE 'table name'SETModify the contentWHEREConditions; UPDATE `products`SET `title` = 'iPhone12', `price` = 1299.88 
    WHERE `title` = 'iPhone';
Copy the code

Query operations against a database

Perform operations on the table using DMQL statements to query the data that meets the conditions.

This is primarily done by using SELECT to retrieve selected rows from one or more tables.

Query format

    SELECT select_expr [, select_expr]...
    [FROM table_references]
    [WHERE where_condition]
    [ORDER BY expr [ASC | DESC]]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [GROUP BY expr]
    [HAVING where_condition]
Copy the code

WHERE Basic condition query

Logical query

And the and, &&. Or or, | |. Between and this will also include the results of both sides. The In keyword is substituted for multiple or queries.

Select * from huawei2000Yuan's cell phoneSELECT * FROM `products` WHERE `brand` = 'huawei' and `price` < 2000;
    SELECT * FROM `products` WHERE `brand` = 'huawei' && `price` < 2000; # query1000to2000Mobile phone (not included1000and2000)SELECT * FROM `products` WHERE price > 1000 and price < 2000;

    # OR: Meet one condition can be # query all Huawei mobile phones or the price is less than1000The mobile phoneSELECT * FROM `products` WHERE brand = 'huawei' or price < 1000; # query1000to2000Mobile phone (including1000and2000)SELECT * FROM `products` WHERE price BETWEEN 1000 and 2000; # View one of multiple resultsSELECT * FROM `products` WHERE brand IN ('huawei'.'millet');
    - equivalent to the
    SELECT * FROM `products` WHERE brand = 'huawei' || brand = 'millet';
Copy the code

A null value query

  • IS NULL
  • IS NOT NULL
    SELECT * FROM `products` WHERE name IS NULL;
    SELECT * FROM `products` WHERE name IS NOT NULL;
Copy the code

Fuzzy query

Fuzzy queries use the LIKE keyword, combined with two special symbols:

  • %Matches any character of any character.
  • _Any character that matches one.
# query all titles starting with vSELECT * FROM `products` WHERE title LIKE 'v%'; # query title with MSELECT * FROM `products` WHERE title LIKE '%M%'; # query title with M must be the third characterSELECT * FROM `products` WHERE title LIKE '__M%';
Copy the code

Sort the query results

ORDER BY has two common values:

  • ASC: ascending order. The default
  • DESC: in descending order.
    SELECT * FROM `products` WHERE brand = 'huawei' or price < 1000 
    ORDER BY price ASC;
Copy the code

You can add more than one sort. As a secondary sort. When the main sort is the same, we can sort by secondary sort.

    SELECT * FROM `products` WHERE brand = 'huawei' or price < 1000 
    ORDER BY price ASC, score DESC;
Copy the code

Paging query

When there is a lot of data in the database, it is not practical to query all the results and display them all at once. In real development, we would require users to pass in fields such as offset, limit, or Page. Their purpose is to allow us to do paging queries in the database;

Its use has [LIMIT {[offset,] row_count | row_count offset offset}].

    SELECT * FROM `products` LIMIT 30 OFFSET 0;
    SELECT * FROM `products` LIMIT 30 OFFSET 30;
    SELECT * FROM `products` LIMIT 30 OFFSET 60; # Another way of writing:offset, row_count
    SELECT * FROM `products` LIMIT 90.30;
Copy the code

Grouping query

We create groups BY GROUP BY. Usually used in conjunction with aggregate functions.

Before we group, we use the aggregate function, which treats the entire table as a group. That is, the aggregate function essentially groups all the data into one group by default.

We first group the data, and then calculate the aggregation function for each group of data. And we can constrain groups by HAVING. Note: WHERE cannot be used after GROUP BY, we can only restrict groups BY HAVING. He said that after the group was divided, the condition was screened.

    SELECT brand,
    COUNT(*) as count,
    ROUND(AVG(price),2) as avgPrice,
    MAX(price) as maxPrice,
    MIN(price) as minPrice,
    AVG(score) as avgScore
    FROM `products` GROUP BY brand
    HAVING avgPrice < 4000 and avgScore > 7;
Copy the code

Common aggregate functions

Note:COUNT(*)COUNT (field)The difference between. The previous step is to count how many records there are in the table. Or the number of non-empty records counted. The latter can also use DISTICT to constrain the same record to be recorded only once. namelyCOUNT (DISTINCT fields)

# Average price of Huawei phonesSELECT AVG(price) FROM `products` WHERE brand = 'huawei'; # Calculate the average score of all phonesSELECT AVG(score) FROM`products`; # Lowest and highest scores on the phoneSELECT MAX(score) FROM `products`;
    SELECT MIN(score) FROM`products`; # Count the total number of votersSELECT SUM(voteCnt) FROM`products`; # count all entriesSELECT COUNT(*) FROM`products`; # number of Huawei phonesSELECT COUNT(*) FROM `products` WHERE brand = 'huawei';
Copy the code

Multiple tables

If we want the two tables to be related. We need to set foreign keys for the contact fields in a table.

Now suppose we have a products and a brand table. By linking the two tables, we can associate the Brand_id in Products with the ID in brand.

    ALTER TABLE `products` ADD FOREIGN KEY (brand_id) REFERENCES brand(id);
Copy the code

How can we make the related fields of two tables be linked?

When we update or delete a foreign key, we can set several values:

  • RESTRICT(Default property) : When updating or deleting a record, the system will check whether the record has associated foreign key records. If so, an error will be reported and the update or deletion is not allowed.

  • NO ACTIONAnd:RESTRICTIs consistent and defined in the SQL standard;
  • CASCADEWhen updating or deleting a record, the system checks whether the record has an associated foreign key record. If so:
    • Update: Then the corresponding record will be updated;
    • Delete: Then the associated records will be deleted together;

  • SET NULL: When updating or deleting a record, the system checks whether the record has associated foreign key records. If so, the corresponding value is set to NULL.

Note: When we use the foreign key and set the type to CASCADE, we delete the external data, and the inner table data will be deleted. However, deleting the inner table data will not affect the appearance.

Try not to use cascade, but it is convenient for special operations. If we delete the comment data and delete the data we want to restore, we can set cascade. Easy to operate.

How do you change the foreign key type in code?

    Look at the table structure to find the foreign key name
    SHOW CREATE TABLE` table name `;Delete the previous foreign key by foreign key name
    ALTER TABLE` ` table nameDROP FOREIGNKEY Foreign KEY name.Add a new foreign key
    ALTER TABLE` ` table nameADD FOREIGNKEY (referenced foreign KEY field)REFERENCESForeign key table (foreign key fields)ONUPDATE Specifies the foreign key typeON DELETEForeign key type when deleting;Look at the table structure to find the foreign key name
    SHOW CREATE TABLE `products`;
    Delete the previous foreign key
    ALTER TABLE `products` DROP FOREIGN KEY products_ibfk_1;
    Add a new foreign key
    ALTER TABLE `products` ADD FOREIGN KEY (brand_id)
    REFERENCES brand(id)
    ON UPDATE CASCADE ON DELETE CASCADE;
    
Copy the code

Join queries between multiple tables

If we want to query the product and display the information related to the corresponding brand, the data is stored in two tables, so we need to conduct multi-table query at this time.

We can use the SQL JOIN operation: JOIN left JOIN right JOIN inner JOIN full JOINA sample SQL statement for the following query. Let’s say there areProducts (ID, brand, title, price, Score, voteCnt, URL, PID, brand_id).Brand (ID (foreign key reference field), name, website, phoneRank)Two tables

Left connectionIf we want to get all the data on the left (mainly the left table) :

LEFT [OUTER] JOIN LEFT [OUTER] JOIN LEFT [OUTER] JOIN LEFT [OUTER] JOIN

    SELECT * FROM `products` LEFT JOIN `brand` ON `products`.brand_id = `brand`.id;

    SELECT * FROM `products` LEFT JOIN `brand` ON `products`.brand_id= `brand`.id
    WHERE brand.id IS NULL;
Copy the code

If we want to get all the data on the right (mainly from the table) :

If the brand_id in the left table matches the id in the right table, the brand_id in the right table will be queried. If the brand_id in the left table matches the ID in the right table, the brand_id will be queriedRIGHT [OUTER] JOINBut the OUTER can be left out.

    SELECT * FROM `products` RIGHT JOIN `brand` ON `products`.brand_id = `brand`.id;
    
    SELECT * FROM `products` RIGHT JOIN `brand` ON `products`.brand_id= `brand`.id
    WHERE products.id IS NULL;
Copy the code

An inner join is actually an association between the table on the left and the table on the right:

Inner joins are occasionally common in development, depending on your scenario. Inner join can be written in other ways:CROSS JOIN.INNER JOIN.JOINWill do.

    SELECT * FROM `products` INNER JOIN `brand` ON `products`.brand_id = `brand`.id;
Copy the code

We’ll see that it has the same effect as before:

    SELECT * FROM `products`, `brand` WHERE `products`.brand_id = `brand`.id;
Copy the code

But they mean different things:

  • Inner join, which means that when two tables are joined, the relationship between the data is constrained to determine the result of the subsequent query.
  • Where condition, on behalf of the cartesian product is calculated first, on the basis of the Cartesian product data screening where condition.

FULL JOIN SQL uses FULL JOIN, but MySQL does not support FULL JOIN, we need to use UNION to implement:

(SELECT * FROM `products` LEFT JOIN `brand` ON `products`.brand_id = `brand`.id)
UNION
(SELECT * FROM `products` RIGHT JOIN `brand` ON `products`.brand_id = `brand`.id);

(SELECT * FROM `products` LEFT JOIN `brand` ON `products`.brand_id = `brand`.id 
WHERE `brand`.id IS NULL)
UNION
(SELECT * FROM `products` RIGHT JOIN `brand` ON `products`.brand_id = `brand`.id 
WHERE `products`.id IS NULL);
Copy the code

How do we convert data from multiple table fields to objects or arrays?

JSON_OBJECT(key, value, [… ) and the JSON_ARRAY() method to convert a field in a table to an object or an array. But if we want to put multiple converted objects in an array, we need to use the JSON_ARRAYAGG() method. More than a pair of

    SELECT products.id as id, 
    products.title as title, 
    products.price as price, 
    products.score as score,
    JSON_OBJECT(
        'id', brand.id, 
        'name', brand.name, 
        'rank', brand.phoneRank, 
        'website', brand.website
    ) as brand
    FROM products LEFT JOIN brand ON products.brand_id = brand.id;
Copy the code

Many to many

    SELECT stu.id, stu.name, stu.age,
    JSON_ARRAYAGG(JSON_OBJECT('id', cs.id, 'name', cs.name)) as courses
    FROM students stu
    LEFT JOIN students_select_courses ssc ON stu.id = ssc.student_id
    LEFT JOIN courses cs ON ssc.course_id= cs.id
    GROUP BY stu.id;
Copy the code

As you can see from the above query, if we want to merge data from general records, we can use groups. And after grouping, if the fields are unique, so many can be retrieved, not just the grouped fields.

Many-to-many relational queries

If we want to link two tables, we need to create an intermediate table. This relational table records data relationships between two tables. Then it is time to query through the multi-table join query syntax.

A sample SQL statement for the following query. Students_select_cources students_select_cources students_select_cources students_select_cources students_select_cources students_select_cources students_select_cources students_select_cources students_select_ Course_id (reference foreign key fields)) three tables. This relational table is used to record the corresponding relationship between student ID and course ID to determine the course selection situation of students.

Querying multiple pieces of Data

Select * from all courses selected by all studentsSELECT
    stu.id studentId, stu.name studentName, cs.id
    courseId, cs.name
    courseName, cs.price
    coursePrice
    FROM `students` stu
    JOIN `students_select_courses` ssc
    ON stu.id = ssc.student_id
    JOIN `courses` cs
    ON ssc.course_id =cs.id; Select * from student; select * from studentSELECT
    stu.id studentId, stu.name studentName, cs.id
    courseId, cs.name
    courseName, cs.price
    coursePrice
    FROM `students` stu
    LEFT JOIN `students_select_courses` ssc
    ON stu.id = ssc.student_id
    LEFT JOIN `courses` cs
    ON ssc.course_id = cs.id;
Copy the code

Example Query single – pick data

What courses did you chooseSELECT
    stu.id studentId, stu.name studentName, cs.id courseId, cs.name courseName, cs.price
    coursePrice
    FROM `students` stu
    JOIN `students_select_courses` ssc
    ON stu.id = ssc.student_id
    JOIN `courses` cs
    ON ssc.course_id = cs.id
    WHERE stu.id = 1; # Which courses did Lily choose?SELECT
    stu.id studentId, stu.name studentName, cs.id courseId, cs.name courseName, cs.price
    coursePrice
    FROM `students` stu
    LEFT JOIN `students_select_courses` ssc
    ON stu.id = ssc.student_id
    LEFT JOIN `courses` cs
    ON ssc.course_id = cs.id
    WHERE stu.id = 5;
Copy the code

MySQL is used in Nodejs

To learn how to execute SQL statements in Node code, we can use two libraries:

  • Mysql: The original Node connects to the mysql database driver.
  • Mysql2: On the basis of mysql, a lot of optimization, improvement.

Currently, I prefer to use mysql2, which is compatible with the mysql API and offers some additional features for faster/better performance.

  • Prepared Statement:

    • Improve performance: send the created statement module to MySQL, then MySQL compiles (parses, optimizes, transforms) the statement module, stores it but does not execute it, and then we give? Provide actual parameters to execute; Even if executed multiple times, it will only compile once, so performance is higher;
    • Prevent SQL injection: later incoming values will not be compiled like the module engine, so some SQL injection content will not be executed;or 1 = 1Will not be enforced;
  • Promise is supported, so we can use async and await syntax.

The basic use

It returns a connection object by calling createConnection() and passing in the corresponding database connection information. The SQL statement is then executed through Query.

    const mysql = require('mysql2');

    // 1. Create a database connection
    const connection = mysql.createConnection({
      host: 'localhost'.port: 3306.database: 'database name'.user: 'root'.password: 'Database password'
    });

    // 2. Execute the SQL statement
    const statement = ` SELECT * FROM products WHERE price > 6000; `
    connection.query(statement, (err, results, fields) = > {
      console.log(results);
    });

Copy the code

Used by preprocessed statements

Through? As placeholders. You then pass in placeholder parameters via execute and execute the SQL statement.

Note: If the statement is executed again, it will be fetched from the LRU (Least Recently Used) Cache, skipping the compilation time to improve performance.

    const mysql = require('mysql2');

    // 1. Create a database connection
        const connection = mysql.createConnection({
          host: 'localhost'.port: 3306.database: 'database name'.user: 'root'.password: 'Database password'
        });

    // 2. Execute the SQL statement
    const statement = ` SELECT * FROM products WHERE price > ? AND score > ? ; `
    // Parameter: SQL statement, passed parameter [], callback function executed
    connection.execute(statement, [6000.7].(err, results) = > {
      console.log(results);
    });
Copy the code

Use of connection pools

Previously we created a connection, but if we have multiple requests, the connection is likely to be occupied, so do we need to create a new connection for each request?

In fact, mysql2 gives us connection pools;

The connection pool can automatically create a connection when needed, and the created connection will not be destroyed, will be put into the connection pool, can continue to use; We can set the LIMIT when creating the connection pool.

    const mysql = require('mysql2');

    1. Create a connection pool
    const connections = mysql.createPool({
      host: 'localhost'.port: 3306.database: 'database name'.user: 'root'.password: 'Database password'
      // Maximum number of connections
      connectionLimit: 10
    });

    // 2. Use connection pools
    const statement = ` SELECT * FROM products WHERE price > ? AND score > ? ; `
    connections.execute(statement, [6000.7].(err, results) = > {
      console.log(results);
    });
Copy the code

How promise is used

The connection object calls the Promise () method.

    const mysql = require('mysql2');

    1. Create a connection pool
    const connections = mysql.createPool({
      host: 'localhost'.port: 3306.database: 'database name'.user: 'root'.password: 'Database password'
      // Maximum number of connections
      connectionLimit: 10
    });

    // 2. Use connection pools
    const statement = ` SELECT * FROM products WHERE price > ? AND score > ? ; `
    connections.promise().execute(statement, [6000.7]).then(([results]) = > {
      console.log(results);
    }).catch(err= > {
      console.log(err);
    });
Copy the code