sqlmanager
v1.0.6
Published
A powerful utility for managing SQL database operations.
Downloads
27
Maintainers
Readme
SQLManager
A powerful utility for managing SQL database operations.
Description
SQLManager
is a module designed to simplify and streamline your interactions with SQL databases. Whether you're using SQLite, MySQL, or any other SQL variant, SQLManager
makes tasks like table creation, query execution, and transaction handling easier than ever.
Usage
To make use of the SQLManager module, first import it:
const SQLManager = require("sqlmanager");
You can then instantiate it with a configuration object detailing your database parameters.
From there, leverage the methods provided by the module to interact with your database.
Arguments
type
: The type of SQL database you're using (e.g., "sqlite", "mysql").path
: The path to your SQLite database file (Required if you're using SQLite).host
: The host of your MySQL server (Required if you're using MySQL).port
: The port of your MySQL server (Required if you're using MySQL).username
: The username for your MySQL database (Required if you're using MySQL).password
: The password for your MySQL database (Required if you're using MySQL).database
: The name of your MySQL database (Required if you're using MySQL).
Examples
SQLite Example:
const SQLManager = require("sqlmanager");
async function main() {
const databaseConfig = {
type: "sqlite",
path: "./database.sqlite",
};
const sqlManager = new SQLManager(databaseConfig);
await sqlManager.createTable((table) => {
table.setName("users").addColumn((column) => {
column.setName("id").setType("INT AUTO_INCREMENT PRIMARY KEY");
})
.addColumn((column) => {
column.setName("user").setType("VARCHAR(255) NOT NULL");
})
.addColumn((column) => {
column.setName("password").setType("VARCHAR(255) NOT NULL");
});
});
}
main();
MySQL Example:
const SQLManager = require("sqlmanager");
async function main() {
const databaseConfig = {
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "password",
database: "test"
};
const sqlManager = new SQLManager(databaseConfig);
await sqlManager.createTable((table) => {
table.setName("users").addColumn((column) => {
column.setName("id").setType("INT AUTO_INCREMENT PRIMARY KEY");
})
.addColumn((column) => {
column.setName("user").setType("VARCHAR(255) NOT NULL");
})
.addColumn((column) => {
column.setName("password").setType("VARCHAR(255) NOT NULL");
});
});
}
main();