
Security News
VulnCon 2025: NVD Scraps Industry Consortium Plan, Raising Questions About Reform
At VulnCon 2025, NIST scrapped its NVD consortium plans, admitted it can't keep up with CVEs, and outlined automation efforts amid a mounting backlog.
@types/mysql
Advanced tools
TypeScript definitions for mysql
The @types/mysql package provides TypeScript type definitions for the mysql package, enabling better development experience with type checking and IntelliSense in TypeScript projects. It does not add any new functionality to mysql itself but allows developers to use mysql in TypeScript applications more effectively.
Connecting to a MySQL database
This code demonstrates how to connect to a MySQL database using the mysql package with TypeScript types provided by @types/mysql. It includes type checking for the connection options.
import * as mysql from 'mysql';
const connection = mysql.createConnection({
host: 'localhost',
user: 'yourusername',
password: 'yourpassword',
database: 'mydb'
});
connection.connect(err => {
if (err) throw err;
console.log('Connected!');
});
Performing a query
This example shows how to perform a basic SQL query to select all records from the 'users' table. The results are logged to the console. The @types/mysql package ensures that the function parameters and return types are correctly typed.
connection.query('SELECT * FROM users', (err, results) => {
if (err) throw err;
console.log(results);
});
Closing the connection
This snippet illustrates how to close the database connection properly. It uses the end method provided by the mysql package, with type safety ensured by @types/mysql.
connection.end(err => {
if (err) return console.log('error:' + err.message);
console.log('Close the database connection.');
});
mysql2 is a fast node.js driver for MySQL with full mysql protocol implementation. It provides promise-based and callback-based interfaces. Compared to @types/mysql, mysql2 comes with built-in TypeScript support, so it doesn't require separate type definitions.
typeorm is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, and Electron platforms and can be used with TypeScript and JavaScript (ES5, ES6, ES7, ES8). It supports the MySQL database among others. Unlike @types/mysql, which only provides type definitions for the mysql package, TypeORM offers a higher-level abstraction for database interactions along with built-in type support.
sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication, and more. While @types/mysql provides type definitions for using mysql in TypeScript, Sequelize offers a comprehensive ORM solution with its own types for TypeScript integration.
npm install --save @types/mysql
This package contains type definitions for mysql (https://github.com/mysqljs/mysql).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mysql.
These definitions were written by William Johnston, Krittanan Pingclasai, James Munro, and Sanders DeNardi.
FAQs
TypeScript definitions for mysql
The npm package @types/mysql receives a total of 4,268,448 weekly downloads. As such, @types/mysql popularity was classified as popular.
We found that @types/mysql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At VulnCon 2025, NIST scrapped its NVD consortium plans, admitted it can't keep up with CVEs, and outlined automation efforts amid a mounting backlog.
Product
We redesigned our GitHub PR comments to deliver clear, actionable security insights without adding noise to your workflow.
Product
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.