文件操作 - mysql2.mjs
返回文件管理
返回主菜单
删除本文件
文件: /var/www/OLD/node_modules/db0/connectors/mysql2.mjs
编辑文件内容
import mysql from "mysql2/promise"; export default function mysqlConnector(opts) { let _connection; const getConnection = async () => { if (_connection) { return _connection; } _connection = await mysql.createConnection({ ...opts }); return _connection; }; return { name: "mysql", dialect: "mysql", getInstance: () => getConnection(), exec(sql) { return getConnection().then((c) => c.query(sql).then((res) => res[0])); }, prepare(sql) { const stmt = { _sql: sql, _params: [], bind(...params) { if (params.length > 0) { this._params = params; } return stmt; }, all(...params) { return getConnection().then((c) => c.query(this._sql, params || this._params).then((res) => res[0])); }, run(...params) { return getConnection().then((c) => c.query(this._sql, params || this._params).then((res) => res[0])); }, get(...params) { return getConnection().then((c) => c.query(this._sql, params || this._params).then((res) => res[0][0])); } }; return stmt; } }; }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件