Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
orm-mysql
Advanced tools
Readme
Tiny ORM with Mysql to tiny project.
$ npm install orm-mysql
file : User.js
var Model = require('orm-mysql')( require('./config-sql.js'));
class User extends Model{
/**
* [constructor description]
* @return {[type]} [description]
*/
constructor(){
super();
this._table = 'User';
this._referer = 'id';
}
/**
* [_treatBeforeInsert description]
* @param {[type]} oData [description]
* @return {[type]} [description]
*/
_treatBeforeInsert( oData){
oData.nom = oData.nom.toLowerCase();
oData.prenom = oData.prenom.toLowerCase();
}
/**
* [completeName description]
* @return {[type]} [description]
*/
get completeName(){
return `${this.nom} ${this.prenom}`;
}
}
module.exports = new User();
var User = require('./user.js');
var oPromise = User.one("`id` = '2'");
var oPromises = User.all();
//ONE USER
oPromise.then(( oUser)=>{
// read
console.log( oUser.nom, oUser.prenom, oUser.completeName);
// update
oUser.nom = 'lorem';
oUser.save().then(()=>{ console.log('saved OK ')});
}).catch((e)=>{
console.log(e);
});
// ALL USERS
oPromises.then( ( aUser)=>{
aUser.map( (oUser)=>{
console.log( oUser.nom, oUser.prenom, oUser.completeName);
})
})
var User = require('./user.js');
var oPromise = User.create({
prenom : "john",
nom : "dupond"
}).then( ( oUser)=>{
console.log( `${oUser.completeName} created`);
});
To read One element
var User = require('./user.js');
User.one(" `prenom` = 'john' ").then( ( oUser)=>{
console.log( `Hi ! ${oUser.completeName}`);
});
To read Multi element
var User = require('./user.js');
User.all().then( ( aUsers)=>{
aUsers.map((oUser)=>{
console.log( `Hi ! ${oUser.completeName}`);
})
});
var User = require('./user.js');
User.one(" `prenom` = 'john' ")
.then( ( oUser)=>{
oUser.nom = "Doe";
oUser.save().then((oUser)=>{
console.log( `${oUser.completeName} updated`);
});
});
var User = require('./user.js');
var oPromiseDel = User.create({
prenom : "alphonse",
nom : "dupond"
})
.then(( oUser)=>{
return oUser.destroy();
});
oPromiseDel.then(()=>{
console.log('sup');
});
var User = require('./user.js');
User.customFind('SELECT * FROM user WHERE prenom = ?', 'john')
.then(( aUsers)=>{
aUsers.map((oUser)=>{
console.log( `custom -> Hi ! ${oUser.completeName}`);
})
});
FAQs
Tiny ORM with Mysql
The npm package orm-mysql receives a total of 1 weekly downloads. As such, orm-mysql popularity was classified as not popular.
We found that orm-mysql 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.