Socket
Socket
Sign inDemoInstall

@types/mysql

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/mysql

TypeScript definitions for mysql


Version published
Weekly downloads
2.9M
increased by7.9%
Maintainers
1
Weekly downloads
 
Created

What is @types/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.

What are @types/mysql's main functionalities?

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.');
});

Other packages similar to @types/mysql

FAQs

Package last updated on 11 Mar 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc