New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

klart

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klart

## About

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
10
42.86%
Maintainers
1
Weekly downloads
 
Created
Source

Klart Tests

About

Klart is a wrapper around node-postgres. It provides a simple interface to make queries towards a PostgreSQL database. Feel free to reach out with any suggestions on how it could be expanded!

Development Setup

The best way to get a working dev environment is to run use docker compose.

commandpurpose
docker-comopse up -dstart environment
yarn sshenter the dev environment
docker-compose downtear the development environment down

Installation

yarn add klart

How to use

All examples use a common Dog-type, looking like this:

type Dog = { name: string; age: number };

Get the first row

import { first } from 'klart';

const fluffy = await first<Dog>('SELECT * FROM dogs WHERE name = $1', ['fluffy']);
console.log(`Retrieved a dog called ${fluffy.name} aged ${fluffy.age}`);

Get all rows

import { rows } from 'klart';

const dogs = await rows<Dog>('SELECT * FROM dogs');
dogs.forEach((dog) => {
  console.log(`Retrieved a dog called ${dog.name} aged ${dog.age}`);
});

Just execute a query

import { run } from 'klart';

//NOTE: no result returned when using `run`
await run('INSERT INTO dogs (name, age) VALUES($1, $2)', ['Fido', 5]);

Configuration

Klart, like node-postgres, picks up the same environment variables as lipq. If you want to ovverride this, you can import withConfiguration from Klart and use that instead (see example below). As Klart really just hands of configuration to node-postgres, details on this page is the best source of information for configuration.

import { withConfiguration } from 'klart';
const { first, rows } = withConfiguration({
  user: 'dbuser',
  host: 'database.server.com',
  database: 'mydb',
  password: 'secretpassword',
  port: 3211,
});

FAQs

Package last updated on 03 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts