@snap-mysql/core
v1.0.0
Published
Shared connection manager and route handlers for the Snap! MySQL project.
Readme
snap-mysql / core
Shared connection manager and route handlers for the Snap! MySQL project. This package contains the logic common to both the standalone server (https://gitlab.com/snap-mysql/server) and the Electron desktop application (https://gitlab.com/snap-mysql/desktop):
- MySQL connection lifecycle management (create, idle reaping, graceful shutdown)
- Express route handlers for all API contract endpoints (connection, query, schema, server introspection)
- Error code mapping and response envelope formatting
The implemented API contract is documented at https://gitlab.com/snap-mysql/api-contract
This package does not include any middleware (CORS, rate limiting, authentication), logging implementation, or configuration loading. Each consumer composes around the shared core with its own middleware and configuration.
Usage
const express = require('express');
const {
createConnectionManager,
createConnectionRouter,
createQueryRouter,
createSchemaRouter,
createServerRouter,
} = require('@snap-mysql/core');
const manager = createConnectionManager({
maxConnections: 30,
idleTimeoutMs: 30 * 60 * 1000,
queryTimeoutMs: 10000,
maxRows: 1000,
logger: console, // any object with info/warn/error methods
fixedMysqlHost: null, // optional SSRF mitigation
fixedMysqlPort: null,
});
const app = express();
app.use(express.json());
app.use('/api/v1/connection', createConnectionRouter(manager));
app.use('/api/v1/connection/:id', createSchemaRouter(manager));
app.use('/api/v1/connection/:id/query', createQueryRouter(manager));
app.use('/api/v1/server', createServerRouter({
version: '1.0.0',
maxRows: manager.config.maxRows,
queryTimeoutMs: manager.config.queryTimeoutMs,
}));
app.listen(3000);Testing
Tests run against a real MySQL instance. In CI, the instance is provided by a GitLab service container (see .gitlab-ci.yml). For local runs, point the TEST_MYSQL_* variables at a local MySQL server:
TEST_MYSQL_HOST=127.0.0.1 TEST_MYSQL_USER=myuser \
TEST_MYSQL_PASSWORD=mypassword TEST_MYSQL_DATABASE=mydb npm testLicense
The Snap! MySQL core package is free software. You may redistribute and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
