quick.pg

Simple to use PostgreSQL client.

Usage no npm install needed!

<script type="module">
  import quickPg from 'https://cdn.skypack.dev/quick.pg';
</script>

README

Quick.PG

Easy, and beginner friendly wrapper for PostgreSQL

Getting Started

Here is an example configuration:

const { QuickPG } = require('quick.pg');

const db = new QuickPG({
  host: 'localhost',
  port: 5432, // optional
  user: 'postgres',
  password: '1234',
  database: 'myDatabase'
})

Or you can do to use a custom table name.

const db = new QuickPG({
  host: 'localhost',
  port: 5432, // optional
  user: 'postgres',
  password: '1234',
  database: 'myDatabase'
}, {
  table: 'test'
});

Lets use the functions!

await db.set('foo', 'bar'); // -> true
await db.get('foo'); // -> 'bar'
await db.all(); // -> { foo: 'bar' }
await db.delete('foo') // -> true
await db.all(); // -> { } 
await db.push('foo', 'bar') // -> true
await db.push('foo', 'baz') // -> true
await db.all() // -> { foo: [ 'bar', 'baz' ] }

Documentation

Useful documentation for quick.pg

Class: QuickPG

Properties

pool: Pool
options: QuickPGOptions

Constructor

constructor(config: PoolConfig, options?: QuickPGOptions)

Methods

all(): Promise<any> // Returns all entries

exists(key: string): Promise<boolean> // Returns true or false, if a key exists

set(key: string, val: any): Promise<boolean> // Sets a value, if it exists it will update it

get(key: string): Promise<any> // Get a value, if it doesnt exist it will return null

delete(key: string): Promise<boolean> // Delete a key, if it doesnt exist it will be seamless.

push(key: string, element: any): Promise<boolean> // Push an element into an array, if the key doesnt exist it will create an array with that element.

query(query: string, data?: Array<any>): Promise<QueryResult>