1.0.0-beta.2 • Published 6 months ago

rel-query-engine v1.0.0-beta.2

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

rel-query-engine

Allows managing multiple databases simultaneously for Relteco-Relnode.

For now, it only supports PostgreSQL

npm i rel-query-engine

Quick Start

// First, create a `connectionList` array and add objects containing connection information, a `nickname` that defines your database, and other relevant details
const connectionList =[
   {name:"LiveDB",engine:Engines.PGSQL,domain:"localhost",port:5432,dbuser:"postgres",dbname:"postgres",dbpassword:"password"},
   {name:"DevDB",engine:Engines.PGSQL,domain:"localhost",port:5432,dbuser:"postgres",dbname:"postgres",dbpassword:"password"},
   {name:"DevMysqlDB",engine:Engines.MYSQL,domain:"localhost",port:6632,dbuser:"root",dbname:"mysql",dbpassword:"password"},
   //... more ...
]
// Now, you can create your `relqueryengine` with the `connectionList` array.
const RQE =new RelQueryEngine(connectionList)

// Now, let's retrieve the `connections` from memory.
  const DBS = RQE.Connections

// Now, you can call the desired database connection using the alias you provided earlier.
  let db =  await DBS.liveDB.LISTDB("postgres")
//                     - ^ -

NOTE :RelQueryEngine dynamically creates the Connections object. This can lead to reminders not working properly in some IDEs.For example, the LISTDB function may not be recognized by the IDE in the above example. To provide an alternative solution to this issue,you can use RelQueryEngine as follows:

// Instead of creating a connectionList array, create a connectionList object.
// Request RelQueryEngine (RQE) to directly return CONNECT with a key as the alias you will provide for your database and object values.
// You can even create this object in a different file, export it, and make it accessible throughout your project.
  const myconnections ={
   LiveDB:RQE.CONNECT({engine:Engines.PGSQL,domain:"localhost",port:5432,dbuser:"postgres",dbname:"postgres",dbpassword:"password"}),
   DevDB:RQE.CONNECT({engine:Engines.PGSQL,domain:"localhost",port:5432,dbuser:"postgres",dbname:"postgres",dbpassword:"password"})
   DevMysqlDB:RQE.CONNECT({engine:Engines.MYSQL,domain:"localhost",port:6632,dbuser:"root",dbname:"mysql",dbpassword:"password"}),

 }

 // Now, you can establish connections based on the aliases from the `myconnections` object.
 // You will notice that your IDE can more easily recognize the LISTDB function.
  let db =  await myconnections.liveDB.LISTDB("postgres")
//                               - ^ -

ENGINE TYPES

Engines

Database engine types

! Currently only postgresql is supported


Options

OPTIONTYPEDEFAULTDESCRIPTION
PGSQLenumPGSQLPostgresql engine
MYSQLenumMYSQLMYSQL engine
MSSQLenumMSSQLMicrosoft Sql engine

  Engines.PGSQL

RELQUERYENGINE

Allows managing multiple databases together for Relteco Relnode.


Options

OPTIONTYPEDEFAULTDESCRIPTION
ConnectionListarrayT_connectionList[]An array of objects of type T_connection objects containing database formation

Examples:

const {RelQueryEngine,Engines} = require("rel-query-engine")

const RQE =new RelQueryEngine(connectionList)

OR

import {RelQueryEngine,Engines} = from "rel-query-engine"

const RQE =new RelQueryEngine(connectionList)

Note: The localhost value assumes that Databases is installed on your system.

ConnectionList

List of database connections to manage

It is an array consisting of objects of type T_connectionList.


  • Type: array[T_connectionList]

  • Default: []


    T_connectionList Object Options

    OPTIONTYPEDEFAULTDESCRIPTION
    namestring""Database nickname
    engineenum "Engines"""Database type
    domainstringlocalhostDatabase address
    portinteger5432Database port
    dbuserstring""Database user name
    dbnamestring""Database name
    dbpasswordstring""Database password

    Example

    const connectionlist=[
    {name:"MyPgDb",engine:Engines.PGSQL,domain:"localhost",port:5432,dbuser:"postgres",dbname:"postgres",dbpassword:"password"}
    ]

Connections

returns database connections in memory

Return Connections


  • Type: array[T_Connections]

  • Default: []

private CREATECONNECTIONS()

creates dynamic database connection object to connection list

and associates this object with Connections.


CONNECT()

Creates database connection based on Engine type

Return connection


Options

OPTIONTYPEDEFAULTDESCRIPTION
infosobject{T_Connect}{}database connection infos of type T_Connect

Example

 const infos ={
 engine:Engines.PGSQL,
 domain:"localhost",
 port:5432,
 dbuser:"postgres",
 dbname:"postgres",
 dbpassword:"password"
 };

 RQE.CONNECT(infos);

T_Connect infos

database connection infos of type T_Connect


T_Connect Options

OPTIONTYPEDEFAULTDESCRIPTION
engineenum "Engines"""Database type
domainstring"localhost"Database address
portinteger5432Database port
dbuserstring""Database user name
dbnamestring""Database name
dbpasswordstring""Database password

1.0.0-beta.2

6 months ago

1.0.0-beta.1

6 months ago