Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
mysql-activerecord
Advanced tools
MySQL ActiveRecord pattern implementation on top of the mysql module.
Active Record Database Pattern implementation for use with node-mysql (https://github.com/felixge/node-mysql) as MySQL connection driver.
It enables similar database operations as in CodeIgniter (a PHP web applications framework). The main benefit and the reason I worked on this was the ability to direct JavaScript objects straight to MySQL queries without having to worry about constructing the query itself. Although Active Record is maybe a tiny step closer to ORM, I see a lot of value in the Active Record as it allows more control over database queries than traditional ORM.
npm install mysql-activerecord
Copyright (c) 2011 Martin Tajur (martin@tajur.ee) Licensed under the GPL license and MIT:
var db = new require('mysql-activerecord').Adapter({
server: 'localhost',
username: 'root',
password: '12345',
database: 'test'
});
db.get('people', function(err, results, fields) {
console.log(results);
});
var data = {
name: 'Martin',
email: 'martin@example.com'
};
db.insert('people', data, function(err, info) {
console.log('New row ID is ' + info.insertId);
});
var data = {
name: 'Martin',
email: 'martin@example.com'
};
db.insert_ignore('people', data, function(err, info) {
console.log('New row ID is ' + info.insertId);
}, 'ON DUPLICATE KEY SET counter = counter + 1');
db
.where({ name: 'Martin' })
.get('people', function(err, results, fields) {
console.log(results);
});
db
.select(['people.id', 'people.name', 'people.email', 'songs.title'])
.join('songs', 'people.favorite_song_id', 'left')
.where({
'people.name': 'Martin',
'songs.title': 'Yesterday'
})
.limit(5, 10)
.order_by('people.name asc')
.get('people', function(err, results, fields) {
console.log(results);
});
var newData = {
name: 'John',
email: 'john@doe.com'
};
db
.where({ id: 1 });
.update('people', newData, function(err) {
if (!err) {
console.log('Updated!');
}
});
db
.where({ id: 1 })
.delete('people', function(err) {
if (!err) {
console.log('Deleted!')
}
});
db
.where("title not like '%Jackson%'")
.where("date_created > '2012-03-10'")
.where({ owner_id: 32 })
.delete('records', function(err) {
if (err) {
console.log('Deleted!')
}
});
FAQs
A lightweight MySQL query builder on top of the node-mysql module.
The npm package mysql-activerecord receives a total of 41 weekly downloads. As such, mysql-activerecord popularity was classified as not popular.
We found that mysql-activerecord demonstrated a not healthy version release cadence and project activity because the last version was released 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
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.