Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
active-record-for-mysql
Advanced tools
Динамическое создание запросов в базу данных MySQL для nodejs
Используется для динамичного формирования наиболее популярных запросов в БД MySQL
CREATE - создание таблицы
DROP - удаление таблицы
INSERT - добавление записи
UPDATE - обновление записей
DELETE - удаление записей
SELECT - получение записей
var model_users = new (require('active-record-for-mysql'))({
table : 'users';
idkey : 'user_id';
table_nick : 'Пользователи',
engine : 'InnoDB',
charset : 'utf8',
fields :
[
{
field : 'user_id',
label : 'ID ПОЛЬЗОВАТЕЛЯ',
type : 'int(11) NOT NULL',
auto : 1,
},
{
field : 'user_name',
label : 'ИМЯ ПОЛЬЗОВАТЕЛЯ',
type : 'varchar(100) NOT NULL',
},
{
field : 'user_family',
label : 'ФАМИЛМЯ ПОЛЬЗОВАТЕЛЯ',
type : 'varchar(100) NOT NULL',
},
{
field : 'user_city_id',
label : 'ID ГОРОДА ПОЛЬЗОВАТЕЛЯ',
type : 'int(11) NOT NULL',
}
]
});
model_users.query_create();
CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `user_name` varchar(100) NOT NULL,`user_family` varchar(100) NOT NULL, `user_city_id` int(11) NOT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
model_users.query_drop();
DROP TABLE IF EXISTS `users`;
var data = {};
model_users.query_select(data);
SELECT * FROM users;
var data = {
fields : ['user_id', 'user_name', 'user_family']
};
model_users.query_select(data));
SELECT `user_id`, `user_name`, `user_family` FROM users;
var data = {
fields : [],
where : {
user_id : 1,
},
limit : 1
};
model_users.query_select(data)
SELECT * FROM users WHERE `user_id`='1' LIMIT 1;
var data = {
fields : ['user_id', 'user_name', 'user_family'],
where : {
user_family : 'Иванов',
'user_name !=' : 'Петр',
'OR user_name !=' : 'Вася',
},
in : {
'user_id' : [1,2,3],
'user_profi' : ['Сантехник', 'Электрик', 'Дворник']
},
};
model_users.query_select(data)
SELECT `user_id`, `user_name`, `user_family` FROM users WHERE `user_family`='Иванов' AND `user_name`!='Петр' OR `user_name`!='Вася' AND `user_id` IN ('1', '2', '3') AND `user_profi` IN ('Сантехник', 'Электрик', 'Дворник');
var data = {
fields : ['user_name', 'user_family'],
group : ['user_name', 'user_family'],
like : {
user_family : 'Ива',
user_name : 'etr%',
},
order : {
user_family : 'asc',
user_age : 'desc'
},
limit : 10,
offset : 5,
};
model_users.query_select(data));
SELECT `user_name`, `user_family` FROM users WHERE `user_family` LIKE '%Ива%' AND `user_name` LIKE 'etr%' GROUP BY user_name, user_family ORDER BY `user_family` ASC, `user_age` DESC LIMIT 5, 10;
var data = {
data : {
user_family : 'Иванов',
user_name : 'Петр',
}
};
model_users.query_insert(data));
INSERT INTO users SET `user_family`='Иванов', `user_name`='Петр';
var data = {
data : {
user_family : 'Иванов',
user_name : 'Петр',
user_passport : require('fs').readFileSync('./uploads/passport.jpg'),
}
};
model_users.query_insert(data));
INSERT INTO users SET `user_family`='Иванов', `user_name`='Петр', ?;
var data = {
data : {
user_family : 'Иванов',
user_name : 'Петр',
},
where : {
user_family : 'Петров',
user_name : 'Иван',
},
in : {
user_id : [1,2,3],
},
like : {
user_family : 'Ива',
user_name : 'etr%',
},
};
model_users.query_update(data));
UPDATE users SET `user_family`='Иванов', `user_name`='Петр' WHERE `user_family`='Петров' AND `user_name`='Иван' AND `user_id` IN ('1', '2', '3') AND `user_family` LIKE '%Ива%' AND `user_name` LIKE 'etr%';
var data = {
data : {
user_family : 'Иванов',
user_name : 'Петр',
user_passport : require('fs').readFileSync('./uploads/passport.jpg'),
},
in : {
user_id : [1,2,3],
},
};
model_users.query_update(data));
UPDATE users SET `user_family`='Иванов', `user_name`='Петр', ? WHERE `user_id` IN ('1', '2', '3');
var data = {
data : {
user_profi : {
case : {
user_code : {
'A 01' : 'Инженер-электрик',
'B 11 3' : 'Слесарь-сантехник 3 категории',
'A 02' : 'Инженер-конструктор',
'С' : 'Разнорабочий',
},
},
}
},
in : {
user_id : [1,2,3],
},
};
model_users.query_update(data));
UPDATE users SET `user_profi` = CASE `user_code` WHEN 'A 01' THEN 'Инженер-электрик' WHEN 'B 11 3' THEN 'Слесарь-сантехник 3 категории' WHEN 'A 02' THEN 'Инженер-конструктор' WHEN 'С' THEN 'Разнорабочий' ELSE `user_profi` END WHERE `user_id` IN ('1', '2', '3');
var data = {
where : {
user_family : 'Иванов',
'user_age >' : 25
},
in : {
user_id : [1,2,3]
},
};
model_users.query_delete(data));
DELETE FROM users WHERE `user_family`='Иванов' AND `user_age`>'25' AND `user_id` IN ('1', '2', '3');
Пример серверного кода для проверки работоспособности расположен в директории "_demo"
node server
http://localhost:2020
FAQs
MySQL active-record query builder for nodejs
We found that active-record-for-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
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.