Datasource

SDK comes with wrappers around different node modules for connecting to different database engines in a single interface named Connection.

The Datasource module is used by Default Repositories as well as its underlying database connection service.

The SDK currently supports the following connections:

Installing dependencies:

    npm i mysql2 -S
import { Datasource } from "@ssofy/node-sdk";
import mysql from "mysql2/promise";
...
const pool = mysql.createPool({
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'root',
    database: 'db',
    waitForConnections: true,
    connectionLimit: 10,
    maxIdle: 10,
    idleTimeout: 60000,
    queueLimit: 0,
    enableKeepAlive: true,
    keepAliveInitialDelay: 0
});

const connection = new Datasource.MySQLPoolConnection(pool)

Installing dependencies:

    npm i pg -S
import { Datasource } from "@ssofy/node-sdk";
import { Pool } from 'pg';
...
const pool = new Pool({
    host: 'localhost',
    user: 'database-user',
    max: 20,
    idleTimeoutMillis: 30000,
    connectionTimeoutMillis: 2000,
})

const connection = new Datasource.PGConnection(pool)

Installing dependencies:

    npm i mongo -S
import { Datasource } from "@ssofy/node-sdk";
import { MongoClient } from "mongodb";
...
const uri = "<connection string uri>";
const client = new MongoClient(uri);

const database = client.db('db');

const connection = new Datasource.MongoDBConnection(database)

Installing dependencies:

    npm i aws-sdk -S
import { Datasource } from "@ssofy/node-sdk";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, GetCommand } from "@aws-sdk/lib-dynamodb";
...
const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);

const connection = new Datasource.DynamoDBConnection(docClient);

Installing dependencies:

    npm i prisma -S
import { Datasource } from "@ssofy/node-sdk";
import { PrismaClient } from '@prisma/client'
...
const prisma = new PrismaClient()

const connection = new Datasource.PrismaConnection(prisma);

Installing dependencies:

    npm i sequelize -S
import { Datasource } from "@ssofy/node-sdk";
import { Sequelize, DataTypes } from 'sequelize';
...
const sequelize = new Sequelize('sqlite::memory:');

const connection = new Datasource.SequelizeConnection(sequelize);

Checkout the Connection interface for the list of available methods.

You may also build your own custom datasource connection by implementing the Connection Interface.

ssofy Knowledge Base
At our core, we believe that staying up-to-date with the latest trends and advancements in Authentication and related areas is essential. That's why we take great pride in keeping you informed with the latest insights, updates, and news in this rapidly evolving landscape.


Do you need support?
SSOfy is by Cubelet Ltd.
Copyright © 2024 Cubelet Ltd. All rights reserved.