http://www.778878.net/docs/#/koa78-mysql78/
- 18 years of ERP development experience, 10 years of cloud development experience, 15 years of stock and futures investment experience, 10 years of investment analysis platform development experience
- Not highly technical, but understands business and excels at solving practical production and operation problems
- Gradually open-sourcing projects that have been optimized over many years and are still running stably
- Encapsulates koa to reduce learning costs
- Stable: Running for years, two single-core 1G machines handle thousands of concurrent requests
- Fast development: A few lines of code handle common APIs like CRUD and batch inserts
- High efficiency: Has a complete low-code front-end and back-end framework, 1 backend can easily support 4+ frontends
- Easy to extend: Business tables correspond to data tables, one directory is a set of small functions, one file is one data table
- Strong adaptability: Runs simultaneously on Alibaba Cloud and Tencent Cloud
- Easy to debug: Can be set to track all calls for certain users, tables, or directories
- Easy to learn: Ten lines of code to get started, hard not to understand
- Easy to maintain: Has complete API call counting and time consumption statistics, as well as WeChat error reporting mechanism
- Fast updates: The main operating project also uses this set, if there are bugs or new features, they will be updated promptly
- Easy to refactor: One directory is a small system, one version is one path, old and new APIs can coexist for a long time, changing tires while driving
- SAAS: Supports data isolation by account or user, same table different permissions, complete permission control
use for nodejs ts
project
See API documentation for details
See API documentation for details
See API documentation for details
Mysql78
is a class that encapsulates MySQL database operations, providing a series of convenient methods to execute SQL queries, updates, and transaction operations.
- Connection pool management
- Support for basic CRUD operations
- Transaction support
- Debugging and logging functionality
- Performance statistics
The constructor accepts a configuration object containing the following properties:
-
host
: Database host address (default is '127.0.0.1') -
port
: Database port (default is 3306) -
max
: Maximum number of connections in the pool (default is 200) -
user
: Database username (default is 'root') -
password
: Database password (required) -
database
: Database name (required) -
isLog
: Whether to enable logging (default is false) -
isCount
: Whether to enable performance statistics (default is false)
Creates commonly used system tables.
Executes a SELECT query and returns the results.
Executes an UPDATE operation and returns the number of affected rows.
Executes an INSERT operation and returns the inserted ID.
doT(cmds: string[], values: any[][], errtexts: string[], logtext: string, logvalue: any[], up: UpInfo): Promise
Executes transaction operations.
Executes a single transaction operation, requires manual connection management.
Gets a database connection.
Releases a database connection.
Adds a warning log.
Saves SQL execution logs.
import Mysql78 from "@www778878net/mysql78"; import UpInfo from "@www778878net/koa78-upinfo";
const config = { host: "localhost", port: 3306, user: "root", password: "password", database: "testdb", isLog: true, isCount: true };
const mysql78 = new Mysql78(config); const upInfo = new UpInfo(null).getGuest();
// Execute a query const result = await mysql78.doGet("SELECT * FROM users WHERE id = ?", [1], upInfo);
// Execute an update const affectedRows = await mysql78.doM("UPDATE users SET name = ? WHERE id = ?", ["John", 1], upInfo);
// Execute an insert const insertId = await mysql78.doMAdd("INSERT INTO users (name, email) VALUES (?, ?)", ["Alice", "alice@example.com"], upInfo);
// Execute a transaction const transactionResult = await mysql78.doT( ["UPDATE users SET balance = balance - ? WHERE id = ?", "UPDATE users SET balance = balance + ? WHERE id = ?"], [[100, 1], [100, 2]], ["Transfer out failed", "Transfer in failed"], "Transfer operation", [100, 1, 2], upInfo );
- After using
getConnection()
to get a connection, remember to usereleaseConnection()
to release the connection. - The
isLog
andisCount
options will affect performance, it is recommended to enable them only during debugging. - For transaction operations, prefer using the
doT
method instead of manually managing transactions. - In production environments, make sure to properly handle all possible errors and exceptions.
you can see test/