New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mikro-orm/postgresql

Package Overview
Dependencies
Maintainers
1
Versions
3278
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mikro-orm/postgresql

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

  • 6.4.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
99K
decreased by-24.71%
Maintainers
1
Weekly downloads
 
Created

What is @mikro-orm/postgresql?

@mikro-orm/postgresql is an ORM (Object-Relational Mapper) for Node.js and TypeScript, specifically designed to work with PostgreSQL databases. It allows developers to interact with PostgreSQL databases using TypeScript/JavaScript objects, providing a high-level abstraction over SQL queries.

What are @mikro-orm/postgresql's main functionalities?

Entity Definition

Defines a User entity with id, name, and email properties. This allows you to map a JavaScript/TypeScript class to a PostgreSQL table.

const { Entity, PrimaryKey, Property } = require('@mikro-orm/core');

@Entity()
class User {
  @PrimaryKey()
  id;

  @Property()
  name;

  @Property()
  email;
}

Database Connection

Initializes a connection to a PostgreSQL database using MikroORM. The configuration includes database name, type, user, and password.

const { MikroORM } = require('@mikro-orm/core');

(async () => {
  const orm = await MikroORM.init({
    entities: [User],
    dbName: 'my-db-name',
    type: 'postgresql',
    user: 'my-db-user',
    password: 'my-db-password',
  });
})();

CRUD Operations

Performs basic CRUD operations. Creates a new user and saves it to the database, then retrieves all users from the database.

const user = new User();
user.name = 'John Doe';
user.email = 'john.doe@example.com';

await orm.em.persistAndFlush(user);

const users = await orm.em.find(User, {});
console.log(users);

Query Builder

Uses MikroORM's query builder to construct and execute a SQL query. This example selects all columns from the User table where the name is 'John Doe'.

const qb = orm.em.createQueryBuilder(User);
qb.select('*').where({ name: 'John Doe' });
const result = await qb.execute();
console.log(result);

Other packages similar to @mikro-orm/postgresql

Keywords

FAQs

Package last updated on 30 Jan 2025

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