1.0.0 • Published 4 months ago

flow-server-plugin-mariadb-chained v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Flow Server Plugin - MariaDB Chained

A MariaDB plugin for Flow Server Framework that provides a chained query builder interface.

Features

  • Fluent, chainable API for building SQL queries
  • Support for all common SQL operations (SELECT, INSERT, UPDATE, DELETE)
  • Connection pooling for improved performance
  • Prepared statements for security
  • Transaction support

Installation

npm install flow-server-plugin-mariadbChained

Usage

Basic Setup

const FlowServer = require('flow-server-framework');
const MariaDBChainedPlugin = require('flow-server-plugin-mariadbChained');

const app = new FlowServer();

// Register the plugin
app.use(new MariaDBChainedPlugin({
  host: 'localhost',
  user: 'root',
  password: 'password',
  database: 'my_database'
}));

// Now you can use the plugin in your services
app.start();

Query Examples

Select

const users = await app.db.table('users')
  .select('id', 'name', 'email')
  .where('active', true)
  .orderBy('name', 'ASC')
  .limit(10)
  .get();

Insert

const result = await app.db.table('users')
  .insert({
    name: 'John Doe',
    email: 'john@example.com',
    active: true
  });

console.log(`Inserted user with ID: ${result.insertId}`);

Update

const result = await app.db.table('users')
  .where('id', 1)
  .update({
    name: 'Jane Doe',
    email: 'jane@example.com'
  });

console.log(`Updated ${result.affectedRows} row(s)`);

Delete

const result = await app.db.table('users')
  .where('active', false)
  .delete();

console.log(`Deleted ${result.affectedRows} row(s)`);

Transactions

await app.db.transaction(async (trx) => {
  await trx.table('accounts')
    .where('id', 1)
    .decrement('balance', 100);
    
  await trx.table('accounts')
    .where('id', 2)
    .increment('balance', 100);
});

License

MIT

1.0.0

4 months ago