Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
objection
Advanced tools
Objection.js is an ORM (Object-Relational Mapper) for Node.js, built on top of the SQL query builder Knex.js. It aims to provide a powerful and flexible way to interact with SQL databases using JavaScript, while maintaining a clean and intuitive API.
Model Definition
Defines a model class that maps to a database table. In this example, the `Person` class represents the `persons` table in the database.
const { Model } = require('objection');
class Person extends Model {
static get tableName() {
return 'persons';
}
}
Querying
Performs a query to fetch all persons older than 30 years. Objection.js provides a fluent API for building SQL queries.
const people = await Person.query().where('age', '>', 30);
Relations
Defines relationships between models. In this example, a `Person` can have many `Animal` pets, establishing a one-to-many relationship.
class Person extends Model {
static get tableName() {
return 'persons';
}
static get relationMappings() {
const Animal = require('./Animal');
return {
pets: {
relation: Model.HasManyRelation,
modelClass: Animal,
join: {
from: 'persons.id',
to: 'animals.ownerId'
}
}
};
}
}
Eager Loading
Fetches related data in a single query. This example fetches persons along with their pets using eager loading.
const peopleWithPets = await Person.query().withGraphFetched('pets');
Validation
Defines a JSON schema for model validation. This example ensures that `firstName` and `lastName` are required fields and must be strings of a certain length.
class Person extends Model {
static get jsonSchema() {
return {
type: 'object',
required: ['firstName', 'lastName'],
properties: {
id: { type: 'integer' },
firstName: { type: 'string', minLength: 1, maxLength: 255 },
lastName: { type: 'string', minLength: 1, maxLength: 255 }
}
};
}
}
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication, and more. Compared to Objection.js, Sequelize has a more extensive feature set but can be more complex to use.
TypeORM is an ORM for TypeScript and JavaScript (ES7, ES6, ES5). It supports many database systems including MySQL, MariaDB, PostgreSQL, SQLite, and more. TypeORM is known for its strong TypeScript support and decorators, making it a good choice for TypeScript projects. It offers similar functionalities to Objection.js but with a different API style.
Bookshelf.js is a JavaScript ORM for Node.js, built on top of the Knex.js SQL query builder. It provides a simple and straightforward way to interact with SQL databases. Bookshelf.js is similar to Objection.js in that both are built on Knex.js, but Bookshelf.js has a more minimalistic approach.
Objection.js is an ORM for Node.js that aims to stay out of your way and make it as easy as possible to use the full power of SQL and the underlying database engine.
Objection.js is built on the wonderful SQL query builder knex. All databases supported by knex are supported by objection.js. SQLite3, Postgres and MySQL are thoroughly tested.
What objection.js gives you:
What objection.js doesn't give you:
Objection.js uses Promises and coding practices that make it ready for the future. We use Well known OOP techniques and ES6 compatible classes and inheritance in the codebase. You can even use things like ES7 async/await using a transpiler such as Babel. Check out our ES6 and ES7 example projects.
Shortcuts:
Blog posts and tutorials:
FAQs
An SQL-friendly ORM for Node.js
The npm package objection receives a total of 124,016 weekly downloads. As such, objection popularity was classified as popular.
We found that objection demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.