1.0.12 • Published 3 months ago

@storecraft/database-postgres v1.0.12

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

Storecraft Postgres driver

SQLite / Postgres / MySQL

Official Postgres driver for StoreCraft using pg package.

npm i @storecraft/database-postgres

usage

import 'dotenv/config';
import http from "node:http";
import { App } from '@storecraft/core'
import { NodePlatform } from '@storecraft/core/platform/node';
import { NodeLocalStorage } from '@storecraft/core/storage/node'
import { Postgres } from '@storecraft/database-postgres';
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js'

const app = new App(
  {
    auth_admins_emails: ['admin@sc.com'],
    auth_secret_access_token: 'auth_secret_access_token',
    auth_secret_refresh_token: 'auth_secret_refresh_token'
  }
)
.withPlatform(new NodePlatform())
.withDatabase(
  new Postgres({
    pool_config: {
      host: process.env.POSTGRES_HOST,
      port: parseInt(process.env.POSTGRES_PORT),
      user: process.env.POSTGRES_USER,
      password: process.env.POSTGRES_PASSWORD,
    }
  })
)
.withStorage(new NodeLocalStorage('storage'))

await app.init();
await migrateToLatest(app.db, false);
 
const server = http.createServer(app.handler).listen(
  8000,
  () => {
    console.log(`Server is running on http://localhost:8000`);
  }
); 

Testing Locally

  1. First setup a postgres server
docker pull postgres
docker run --name some-postgres -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin \
          -e PGDATA=/var/lib/postgresql/data/pgdata \
	        -v $(pwd):/var/lib/postgresql/data \
          -p 5432:5432 -d postgres
  1. create Environment

create .env file with

POSTGRES_USER='user'
POSTGRES_PASSWORD='password'
POSTGRES_PORT=5432
POSTGRES_HOST='localhost'
  1. Run tests/runner.test.js
npm run database-postgres:test
Author: Tomer Shalev <tomer.shalev@gmail.com>
1.0.11

3 months ago

1.0.12

3 months ago

1.0.10

4 months ago

1.0.9

4 months ago

1.0.8

4 months ago

1.0.7

6 months ago

1.0.6

7 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

10 months ago