Socket
Socket
Sign inDemoInstall

uranio

Package Overview
Dependencies
152
Maintainers
2
Versions
98
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    uranio

Uranio is a type-safe ODM for MongoDB


Version published
Maintainers
2
Install size
47.2 MB
Created

Readme

Source

Uranio

uranio logo

Uranio is the lightest Typescript Object Document Mapper (ODM) for MongoDB and Object Relational Mapping (ORM) for MySQL.
It creates a client for querying collections/tabls in a database by just parsing the types in a repository.

It is the simplest and fastest way to query a database without the need to build a Data Access Layer (DAL) from the defined types.

Install

yarn add uranio

How it works

Run:

uranio generate -d mongodb
// or
uranio generate -d mysql

The above command search for all interfaces in your repository that extends the uranio.atom interface.
For each of these interfaces it creates a method to query a collection with a name of the interface.

For example if in your code you have:

import uranio from 'uranio';

interface Product extends uranio.atom {
  title: string;
  description: string;
  price: number;
}

then Uranio generates a method for querying a collection named products:

import uranio from 'uranio';

const uri = process.env.MONGO_DATABASE_URI || '';
const db_name = process.env.MONGO_DATABASE_NAME || '';

const urn = uranio.MongoDBClient({uri, db_name});

// Get all products
const products = await urn.products.get_atoms({});

// Create a product
await urn.products.put_atom({
  title: 'Uranio mug',
  description: 'A radioactive mug for your coding breakfast',
  price: 4.99
});

Primary index _id for MongoDB

When extending an interface with uranio.atom (MongoDB) this add a primary index attribute _id to the interface, so there is no need to add it manually.

import uranio from 'uranio';

interface Product extends uranio.atom {
  title: string;
  description: string;
  price: number;
}
// It resolves in:
// {
//  _id: string;
//  title: string;
//  description: string;
//  price: number;
// }

Credits

Logo credits https://www.jacopotripodi.com/

FAQs

Last updated on 24 Feb 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc