
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
A robust and type-safe ORM (Object-Relational Mapping) library for Node.js written in TypeScript. DBLink makes database interactions intuitive and maintainable with a decorator-based approach and strong typing throughout the entire query pipeline.
A robust and type-safe ORM (Object-Relational Mapping) library for Node.js written in TypeScript. DBLink makes database interactions intuitive and maintainable with a decorator-based approach and strong typing throughout the entire query pipeline.
DBLink provides a powerful and intuitive way to interact with databases using TypeScript's type system. It leverages TypeScript decorators to define entity-database mappings with strong typing throughout the entire query pipeline.
npm install dblink
# or
yarn add dblink
# or
pnpm add dblink
DBLink requires a database adapter to connect to your specific database. Install the appropriate adapter for your database system:
npm install dblink-mysqlnpm install dblink-pgnpm install dblink-sqlitenpm install dblink-mssqlnpm install dblink-oracleEach adapter provides optimized connectivity and query translation for its specific database system. For complete installation and configuration details, see the adapter-specific documentation.
DBLink is designed to be easy to set up and integrate with your TypeScript/Node.js projects. Follow these steps to get started:
tsconfig.json:{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
// other options...
}
}
DBLink relies on several key dependencies:
reflect-metadata: For decorator metadataclass-transformer: For entity serialization/deserializationdblink-mysql, dblink-postgres)import { Table, Column, Id, Foreign } from 'dblink';
@Table('users')
class User {
@Id()
id!: number;
@Column('first_name')
firstName!: string;
@Column('last_name')
lastName!: string;
@Column()
email!: string;
@Column('created_at')
createdAt!: Date;
}
@Table('orders')
class Order {
@Id()
id!: number;
@Column('user_id')
userId!: number;
@Foreign(User, (builder, parent) => builder.id.eq(parent.userId))
user!: User;
@Column('order_date')
orderDate!: Date;
@Column('total_amount')
totalAmount!: number;
}
import { Context } from 'dblink';
import { TableSet } from 'dblink';
import { User, Order } from './entities';
import MysqlDblink from 'dblink-mysql'; // or any other database driver
class DbContext extends Context {
user = new TableSet(User);
order = new TableSet(Order);
}
// Create a database context with connection options
const db = new DbContext(new MysqlDblink({
host: 'localhost',
port: 3306,
username: 'root',
password: 'password',
database: 'mydatabase'
}));
await db.init();
export default db;
// Find a single user
const user = await db.users
.where(u => u.id.eq(1))
.single();
// Find all users with filtering and ordering
const users = await db.users
.where(u => u.lastName.eq('Smith'))
.orderBy(u => u.firstName.asc())
.list();
// Find user with slelected columns
const userWithSelectedColumns = await db.users
.where(u => u.id.eq(1))
.select('id', 'firstName', 'lastName')
.single();
// Relationship queries
const ordersWithUsers = await db.orders
.include('user')
.where(o => o.totalAmount.eq(100))
.list();
// Pagination
const page = await db.users
.orderBy(u => u.createdAt.desc())
.limit(10,10) // Skip 10, take 10
.list();
// Aggregations
const totalOrders = await db.orders
.where(o => o.userId.eq(1))
.count();
// Insert a new user
const newUser = new User();
newUser.firstName = 'John';
newUser.lastName = 'Doe';
newUser.email = 'john@example.com';
newUser.createdAt = new Date();
await db.users.insert(newUser);
// Update a user
const userToUpdate = await db.users
.where(u => u.id.eq(1))
.single();
if (userToUpdate) {
userToUpdate.email = 'new-email@example.com';
await db.users.update(userToUpdate, 'email');
}
// Delete a user
const userToDelete = await db.users
.where(u => u.id.eq(2))
.single();
if(userToDelete) {
await db.users.delete(userToDelete);
}
// Start a transaction
const transactionContext = await db.initTransaction();
try {
// Perform multiple operations in a transaction
const user = new User();
user.firstName = 'Transaction';
user.lastName = 'Test';
user.email = 'transaction@example.com';
user.createdAt = new Date();
await transactionContext.users.insert(user);
const order = new Order();
order.userId = user.id;
order.orderDate = new Date();
order.totalAmount = 99.99;
await transactionContext.orders.insert(order);
// Commit the transaction
await transactionContext.commit();
} catch (error) {
console.error('Transaction failed:', error);
await transactionContext.rollback();
}
const query = 'SELECT * FROM users WHERE age > 18';
// Execute raw SQL queries
const results = await db.run(query);
// Stream large result sets
const stream = await db.stream(query);
stream.on('data', (user) => {
console.log(user.firstName);
});
DBLink supports various relationship types between entities:
@Table('departments')
class Department {
@Id()
id!: number;
@Column()
name!: string;
// Virtual property for employees in this department
@Foreign(Employee, (e, dept) => e.departmentId.eq(dept.id))
employees!: Employee[];
}
@Table('employees')
class Employee {
@Id()
id!: number;
@Column('department_id')
departmentId!: number;
@Foreign(Department, (d, emp) => d.id.eq(emp.departmentId))
department!: Department;
}
DBLink provides a comprehensive set of query operators:
eq, ne, gt, gte, lt, lteand, or, notlikeinisNull, isNotNullbetweenadd, subtract, multiply, dividecount, sum, average, min, maxDBLink uses decorators to map TypeScript classes to database entities:
Marks a class as a database table entity.
tableName: Optional custom table name (defaults to class name if not provided)Maps a property to a database column.
columnName: Optional custom column name (defaults to property name if not provided)Marks a property as the primary key for the entity.
Defines a relationship between entities.
entityType: The related entity classrelationshipFunction: A function defining how the entities are relatedExample:
@Foreign(User, (builder, parent) => builder.id.eq(parent.userId))
user!: User;
For detailed API documentation, please see the TypeScript definitions in the source code.
@Table()reflect-metadata is imported at the application entry point@Column()include() selectively to avoid N+1 query problemsstream() instead of list()This project is licensed under the ISC License - see the LICENSE file for details.
FAQs
A robust and type-safe ORM (Object-Relational Mapping) library for Node.js written in TypeScript. DBLink makes database interactions intuitive and maintainable with a decorator-based approach and strong typing throughout the entire query pipeline.
The npm package dblink receives a total of 21 weekly downloads. As such, dblink popularity was classified as not popular.
We found that dblink demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.