# @cocalc/database

> CoCalc: code for working with our PostgreSQL database

Latest version **0.35.8** (published 2023-01-04) · SEE LICENSE.md license · 0 weekly downloads

## Install

```sh
npm install @cocalc/database
pnpm add @cocalc/database
yarn add @cocalc/database
bun add @cocalc/database
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.35.8 |
| Published | 2023-01-04 |
| First published | 2021-10-18 |
| Weekly downloads | 0 |
| License | SEE LICENSE.md |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 21 |
| Unpacked size | 1.4 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1288 |
| Author | SageMath, Inc. |
| Maintainers | wstein, hasch |
| Keywords | postgresql, cocalc |

## Links

- npm: https://www.npmjs.com/package/@cocalc/database
- Repository: https://github.com/sagemathinc/cocalc
- Issues: https://github.com/sagemathinc/cocalc/issues
- npm.io page: https://npm.io/package/@cocalc/database

## Dependencies (21)

- [pg](https://npm.io/package/pg.md) ^8.7.1
- [read](https://npm.io/package/read.md) ^1.0.7
- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [async](https://npm.io/package/async.md) ^1.5.2
- [debug](https://npm.io/package/debug.md) ^4.3.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [awaiting](https://npm.io/package/awaiting.md) ^3.0.0
- [@types/pg](https://npm.io/package/@types/pg.md) ^8.6.1
- [immutable](https://npm.io/package/immutable.md) ^3.8.2
- [lru-cache](https://npm.io/package/lru-cache.md) ^6.0.0
- [validator](https://npm.io/package/validator.md) ^13.6.0
- [random-key](https://npm.io/package/random-key.md) ^0.3.2
- [@types/uuid](https://npm.io/package/@types/uuid.md) ^8.3.1
- [prom-client](https://npm.io/package/prom-client.md) ^13.0.0
- [@cocalc/util](https://npm.io/package/@cocalc/util.md) ^1.76.5
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.176
- [@cocalc/server](https://npm.io/package/@cocalc/server.md) ^0.44.5
- [@cocalc/backend](https://npm.io/package/@cocalc/backend.md) ^1.21.1
- [@types/lru-cache](https://npm.io/package/@types/lru-cache.md) ^5.1.1
- [async-await-utils](https://npm.io/package/async-await-utils.md) ^3.0.1
- [sql-string-escape](https://npm.io/package/sql-string-escape.md) ^1.1.6

## Recent versions

- 0.35.8 (latest) — 2023-01-04
- 0.28.4 (next-sso) — 2022-08-24
- 0.23.0 (boost-dedi-5796) — 2022-05-11
- 0.18.4 (pr-5795) — 2022-04-05
- 0.18.1 (upd-hub-db-test) — 2022-04-01
- 0.16.0 (pr-5775) — 2022-03-15
- 0.15.0 (pr-5723) — 2022-03-06
- 0.7.1 (pr-5592) — 2021-12-03
- 1.0.0 (pr5560) — 2021-11-11
- 0.35.7 — 2023-01-03
- 0.35.6 — 2023-01-03
- 0.35.5 — 2023-01-03
- 0.35.4 — 2023-01-02
- 0.35.3 — 2023-01-02
- 0.35.2 — 2023-01-02
- … 55 more at https://npm.io/package/@cocalc/database/versions

## README

# @cocalc/database

This package connects the hub and nextjs servers to the PostgreSQL database, and implements some nontrivial functionality to support these servers.  In particular:

- It implements changefeeds and user queries, which provides a pure JSON language similar to the basics of GraphQL for setting, getting, and subscribing to data in the database.  This uses PostgreSQL LISTEN/NOTIFY to send push notifications about changes to tables.  It's specifically designed for our data structures, of course, and is not generic.  The data structures are currently defined in `@cocalc/util/db-schema`.

## Notes

**WARNING**: This is the single scariest chunk of CoffeeScript left in CoCalc! 

**Temporary Warning:** There is a circular dependency between this package and @cocalc/server right now.  That's necessary while we rewrite the coffeescript code.  What happened was that these files `postgres-*.coffee` ended up implementing hundreds amount of "server functions"  that have nothing to do with basic database functionality.  They need to be rewritten in lots of small typescript files, mostly in `@cocalc/server`.

---
_Source: https://npm.io/package/@cocalc/database · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
