This package has been deprecated

Author message:

Not supported

hub-postgre-manager
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

PostgreManager

Программа для работы с базой данных postgre

Установка

Для установки программы используйте npm:

npm i postre-manager

Использование postgre-manager.installRouter() c Express js

Подключение модуля

Подключите модуль postgre-manager и в методе use приложения Express укажите на использование installRouter.

   import * as Express from 'express';
   const app = Express();

   import * as Http from 'http';
   const server = new Http.Server(app);
   
   import { InstallRouter, IPostgreConnectionOptions } from 'postgre-manager';

   ...

   app.use('/install/db', InstallRouter(server, "db", <IPostgreConnectionOptions>options, queries));

где,

server: Http.Server,
"db": псевдоним, используется при подключении нескольких InstallRouter,
options: IPostgreConnectionOptions - параметры подключения к базе данных postgre,
queries: Array<namedQuery> - массив запросов создания базы данных.

Параметры подключения к базе данных postgre

	interface IPostgreConnectionOptions {
		host: string,
		user?: string, // default process.env.PGUSER || process.env.USER
		password?: string, //default process.env.PGPASSWORD
		database?: string, // default process.env.PGDATABASE || process.env.USER
		templateDatabase?: string, //template database on which creates new database
		port?: number, // default process.env.PGPORT
		statement_timeout: number, // number of milliseconds before a query will time out default is no timeout

		// number of milliseconds to wait before timing out when connecting a new client
		// by default this is 0 which means no timeout
		connectionTimeoutMillis?: number,
		// number of milliseconds a client must sit idle in the pool and not be checked out
		// before it is disconnected from the backend and discarded
		// default is 10000 (10 seconds) - set to 0 to disable auto-disconnection of idle clients
		idleTimeoutMillis?: number,
		// maximum number of clients the pool should contain
		// by default this is set to 10.
		max?: number,
	}

Пример массива запросов создания базы данных

	const queries: Array<namedQuery> = [
		{
			name: `Создание базы данных "db"`,
			query: `CREATE DATABASE db`
		}
	]

Пример использования двух InstallRouter()

app.use('/install/products',
    (req: Express.Request, res: Express.Response, next: Express.NextFunction) => {
        if (req.isAuthenticated()) {
			next();    
        } else {
            res.send('Login failed');
        }
    },
    InstallRouter(server, "productsDB", <IPostgreConnectionOptions>productsDBConnectionOptions, installProductsDBQueries)
);

app.use('/install/users',
    (req: Express.Request, res: Express.Response, next: Express.NextFunction) => {
        if (req.isAuthenticated()) {
			next();    
        } else {
            res.send('Login failed');
        }
    },
    InstallRouter(server, "usersDB", <IPostgreConnectionOptions>usersDBConnectionOptions, installusersDBQueries)
);

Dependencies (4)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i hub-postgre-manager

    Weekly Downloads

    0

    Version

    1.1.4

    License

    none

    Unpacked Size

    538 kB

    Total Files

    34

    Last publish

    Collaborators

    • ahmoleg