
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
baracota-node-db
Advanced tools
A modern, type-safe ORM for Node.js with support for MySQL and SQLite databases, featuring:
npm install baracota-node-db mysql2 # For MySQL
# or
npm install baracota-node-db sqlite3 # For SQLite
import { initORM } from 'baracota-node-db';
// Initialize with MySQL
await initORM({
client: 'mysql',
connection: {
host: 'localhost',
user: 'root',
password: '',
database: 'test'
}
});
// Or with SQLite
await initORM({
client: 'sqlite',
connection: {
filename: './database.sqlite'
}
});
import { Model, PrimaryKey, Fields, HasMany } from 'baracota-node-db';
@Model('users')
@Fields(['id', 'name', 'email'])
class User extends BaseModel {
@PrimaryKey('user_id')
id: number;
@HasMany()
posts: Post[];
}
@Model('posts')
@Fields(['id', 'title', 'content', 'user_id'])
class Post extends BaseModel {
// Model methods...
}
class User extends BaseModel {
protected table = 'users';
protected primaryKey = 'id';
protected allowedFields = ['id', 'name', 'email'];
// Define relationships
static {
this.hasMany(Post, 'user_id');
}
}
// Create a user
const userId = await User.insert({
name: 'John Doe',
email: 'john@example.com'
});
// Find with relationships
const user = await User.with('posts').find(userId);
console.log(user.posts);
// Complex query
const activeUsers = await User
.where('status', 'active')
.where('created_at', '>', new Date('2023-01-01'))
.orderBy('name', 'ASC')
.limit(10)
.get();
// Transaction
await transaction(async (trx) => {
const user = new User(trx);
const post = new Post(trx);
const userId = await user.insert({ name: 'Alice' });
await post.insert({ title: 'First Post', user_id: userId });
});
Feature | MySQL | SQLite |
---|---|---|
CRUD | ✅ | ✅ |
Transactions | ✅ | ✅ |
Relations | ✅ | ✅ |
Soft Deletes | ✅ | ✅ |
Decorator | Description | Example |
---|---|---|
@Model() | Defines table name | @Model('users') |
@Fields() | Whitelists allowed fields | @Fields(['id', 'name']) |
@PrimaryKey() | Specifies primary key | @PrimaryKey('user_id') |
@HasMany() | Defines 1-to-many relationship | @HasMany() |
@BelongsTo() | Defines many-to-1 relationship | @BelongsTo() |
@BeforeCreate | Lifecycle hook before creation | @BeforeCreate() |
// Basic queries
Model.find(id)
Model.findAll()
Model.insert(data)
Model.update(id, data)
Model.delete(id)
// Query builder
Model.where(field, value)
Model.whereIn(field, values)
Model.orderBy(field, direction)
Model.limit(count)
Model.offset(count)
// Advanced
Model.with(relations) // Eager load
Model.transaction(callback) // Run in transaction
Model.softDelete() // Mark as deleted
Model.restore() // Unmark as deleted
Initialize with these options:
await initORM({
client: 'mysql' | 'sqlite',
connection: {
// MySQL
host?: string,
user?: string,
password?: string,
database?: string,
port?: number,
// SQLite
filename?: string
},
pool?: {
min?: number,
max?: number
},
modelDefaults?: {
timestamps?: boolean,
createdAt?: string,
updatedAt?: string,
softDeletes?: boolean,
deletedAt?: string
}
});
// Test setup
beforeAll(async () => {
await initORM({
client: 'sqlite',
connection: { filename: ':memory:' } // In-memory database
});
});
// Example test
test('create user', async () => {
const id = await User.insert({ name: 'Test' });
const user = await User.find(id);
expect(user.name).toBe('Test');
});
BaseModel.initialize()
with initORM()
git checkout -b feature/fooBar
)git commit -am 'Add some fooBar'
)git push origin feature/fooBar
)MIT © M.S.B
FAQs
TypeScript ORM with multi-database support
The npm package baracota-node-db receives a total of 7 weekly downloads. As such, baracota-node-db popularity was classified as not popular.
We found that baracota-node-db demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.