Soap Mysql
MySql for SoapJS This page and the plugin itself are still in development, a lot will change.
This package provides MySql integration for the SoapJS framework, enabling seamless interaction with MySql databases and ensuring that your data access layer is clean, efficient, and scalable.
Features
Easy-to-use MySql collections and query factories.
Integration with the SoapJS framework for structured, clean architecture.
Support for MySql operations such as find, insert, update, and delete.
Custom error handling to improve debugging and error resolution.
Installation
Remember to have mysql2 and @soapjs/soap installed in your project in which you want to use this package.
Install the package using npm:
npm install @soapjs/soap-node-mysqlUsage
Import the necessary components from the package:
import { MySqlCollection, MySqlConfig, MySqlQueryFactory, MySqlSource, } from '@soapjs/soap-node-mysql';Set up your MySql configuration:
const config = new MySqlConfig({ database: 'yourDatabase', hosts: ['localhost'], ports: ['27017'], user: 'yourUser', password: 'yourPassword' // additional config parameters });Create a new
MySqlSourceinstance:const mysqlSource = await MySqlSource.create(config);Utilize
MySqlQueryFactoryfor building queries and aggregations:const queryFactory = new MySqlQueryFactory(); const params = FindParams.create({ where: new Where().valueOf('customer').isEq(userId) }); const queryParts = queryFactory.createFindQuery(params);Use
MySqlCollectionto perform database operations:const collection = new MySqlCollection<MyDocumentType>(mysqlSource, 'myCollectionName'); const documents = await collection.find(queryParts); /* // You can also use a raw SQL query as a string. Then remember to validate this query beforehand const documents = await collection.find(`SELECT * FROM ${collection.collectionName} ...`); */
Last updated