Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/database/index.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6PostgreSQL database entry point.7Do not import any of the submodules directly unless you8know exactly what you're doing.910COPYRIGHT : (c) 2021 SageMath, Inc.11*/1213import { setupRecordConnectErrors } from "./postgres/record-connect-error";1415import { PostgreSQL } from "./postgres/types";1617const base = require("./postgres-base");1819export const {20pg_type,21expire_time,22one_result,23all_results,24count_result,25PROJECT_COLUMNS,26PUBLIC_PROJECT_COLUMNS,27} = base;2829// Add further functionality to PostgreSQL class -- must be at the bottom of this file.30// Each of the following calls composes the PostgreSQL class with further important functionality.31// Order matters.3233let theDB: PostgreSQL | undefined = undefined;3435export function db(opts = {}): PostgreSQL {36if (theDB === undefined) {37let PostgreSQL = base.PostgreSQL;3839for (const module of [40"server-queries",41"blobs",42"synctable",43"user-queries",44"ops",45]) {46PostgreSQL = require(`./postgres-${module}`).extend_PostgreSQL(47PostgreSQL,48);49}50const theDBnew = new PostgreSQL(opts);51setupRecordConnectErrors(theDBnew);52theDB = theDBnew;53}5455if (theDB == null) {56throw new Error("Fatal error setting up PostgreSQL instance");57}58return theDB;59}6061import getPool from "./pool";62export { stripNullFields } from "./postgres/util";63export { getPool };646566