Initial upload with MSSQL and MariaDB implemented.

This commit is contained in:
2025-08-21 02:46:01 -04:00
commit 57430daf33
10 changed files with 3043 additions and 0 deletions

68
readme.md Normal file
View File

@@ -0,0 +1,68 @@
## JS DB Connector Service Guide
This set of modules is intended to serve as a general purpose toolkit for building Node.js applications with a database-type agnostic SQL backend. The audience at creation is myself, as I wanted a reusable module for communicating with my SQL backends in Node.js projects.
## Features
At the moment, CRUD operations against Microsoft SQL Server and MariaDB servers are supported. I plan to implement support for interoperability with Postgres, Oracle, and MongoDB as well to provide the most possible utility in this package. An example implementation is available in the included server.js:
```javascript
// server.js
require('dotenv').config();
const express = require('express');
const app = express();
const queryExecutor = require('./services/dbconnector/queryExecutor');
const cors = require('cors');
app.use(express.json());
app.use(cors());
/**
* Example route to demonstrate CRUD operations.
*/
app.post('/api/query', async (req, res) => {
try {
const { table, operation, params } = req.body;
const result = await queryExecutor.executeQuery(table, operation, params);
res.status(200).json(result);
} catch (err) {
console.error('Error executing query:', err);
res.status(500).json({ error: err.message });
}
});
const PORT = process.env.PORT || 3100;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
```
Additionally, the script `client.js` which runs simulated interactions with the server.js contains the following example for a request to the sample API route:
```javascript
async function testQuery(table, operation, params) {
try {
const response = await axios.post('http://localhost:3100/api/query', {
table,
operation,
params
});
console.log(response.data);
} catch (error) {
console.error('Error executing query:', error.response ? error.response.data : error.message);
}
}
```
The following environment variables are used to control the operation of the DB connector:
```
DB_USER= # A user with permissions to manage the database
DB_PASSWORD= # Password for DB_USER
DB_SERVER= # Hostname or IP of the database server
DB_PORT= # Port if not using default for the database type
DB_DATABASE= # Database to be used. As written, only a single database is supported
DB_TYPE= # MSSQL and MARIADB are implemented. ORACLEDB and POSTGRES are planned.
DB_TRUST_CERT= # Trust the local system SSL certificate, useful for developing against MSSQL server.
```
## Testing
To test the function of these modules, run "node server.js" in the project root, and post to http://localhost:3100/api/query. You can instead run client.js to automatically attempt each query type against the default server URL.