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

uranio

Package Overview
Dependencies
Maintainers
2
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uranio

Uranio is a type-safe ODM for MongoDB

  • 0.1.34
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
95
decreased by-42.07%
Maintainers
2
Weekly downloads
 
Created
Source

Uranio

uranio logo

Uranio is a Typescript Object Document Mapper (ODM) for MongoDB.
It creates a client for querying collections in a database by just parsing the types in a repository.

Install

yarn add uranio

How it works

Run:

uranio generate

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.Client({uri, db_name});

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

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

Uranio types

You can use uranio types to better define the schema of your collections.
For example:

interface Customer extends uranio.atom {
  email: uranio.unique<string>;
}

Primary index _id

When extending an interface with uranio.atom 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

Package last updated on 18 Jan 2024

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