Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nukak

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nukak

flexible and efficient ORM, with declarative JSON syntax and smart type-safety

  • 0.1.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
64
decreased by-46.22%
Maintainers
1
Weekly downloads
 
Created
Source

code

tests coverage status license npm version

nukak is a powerful and efficient ORM, designed from the ground up to be fast, secure, and easy to use. It is inspired by other ORMs such as TypeORM and MongoDB driver, and has been ideated to rely on serializable JSON syntax for easy transport across platforms.

 

Features

  • Serializable queries: the syntax is 100% valid JSON allowing the queries to be transported across platforms with ease.
  • Type-safe queries: auto-completion and validation of queries is done by TypeScript while coding.
  • Context-aware queries: TypeScript infers the appropriate operators and fields based on each part of the query.
  • High performance: the generated queries are efficient, safe, and human-readable.
  • Declarative and imperative transactions.
  • Modern Pure ESM approach. ESM is natively supported by Node.js 12 and later.
  • soft-delete, virtual fields, repositories, connection pooling.
  • Supports the Data Mapper pattern for maintainability and scalability.
  • Transparent support for inheritance between entities.
  • Support for projection, filtering, sorting, and other operations on any level of the query, including relations and their fields.
  • Unified syntax across Databases: providing a standard API and transparently transforming queries according to the configured database.

 

Install

  1. Install the core package:

    npm install nukak --save
    
  2. Install one of the specific adapters for your database:

DatabaseDriverNukak Adapter
MySQLmysql2nukak-mysql
MariaDBmariadbnukak-maria
SQLitesqlite sqlite3nukak-sqlite
PostgreSQLpgnukak-postgres
MongoDBmongodbnukak-mongo

For example, for Postgres:

npm install pg nukak-postgres --save
  1. Additionally, your tsconfig.json may need the following flags:

    "target": "es2020",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
    

 

Configure

A default querier-pool can be set in any of the bootstrap files of your app (e.g. in the server.ts).

import { setQuerierPool } from 'nukak';
import { PgQuerierPool } from 'nukak-postgres';

export const querierPool = new PgQuerierPool(
  {
    host: 'localhost',
    user: 'theUser',
    password: 'thePassword',
    database: 'theDatabase',
  },
  // optionally, a logger can be passed to log the generated SQL queries
  { logger: console.log }
);

// the default querier pool that `nukak` will use
setQuerierPool(querierPool);

 

Define the entities

Take any dump class (aka DTO) and annotate it with the decorators from nukak/entity.

import { v4 as uuidv4 } from 'uuid';
import { Id, Field, Entity } from 'nukak/entity';

@Entity()
export class User {
  @Id({ onInsert: uuidv4 })
  id?: string;
  @Field()
  name?: string;
  @Field()
  email?: string;
  @Field()
  password?: string;
}

 

Manipulate the data

import { getQuerier } from 'nukak';
import { User } from './shared/models/index.js';

async function findLastUsers(limit = 10) {
  const querier = await getQuerier();
  const users = await querier.findMany(User, {
    $project: ['id', 'name', 'email'],
    $sort: { createdAt: -1 },
    $limit: limit,
  });
  await querier.release();
  return users;
}

async function createUser(body: User) {
  const querier = await getQuerier();
  const id = await querier.insertOne(User, body);
  await querier.release();
  return id;
}

 

Learn more about nukak at its website https://nukak.org

Keywords

FAQs

Package last updated on 06 Dec 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc