Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@types/mysql
Advanced tools
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
Additional Details
These definitions were written by William Johnston https://github.com/wjohnsto, Kacper Polak https://github.com/kacepe, Krittanan Pingclasai https://github.com/kpping, James Munro https://github.com/jdmunro.
FAQs
TypeScript definitions for mysql
The npm package @types/mysql receives a total of 2,498,008 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.