Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
_ __ ___ _____ ___ _ __ _ __ ___
| '_ ` _ \| __ \/ _ \| `__/| '_ ` _ \
| | | | | | |___| |_| | | | | | | | |
|_| |_| |_|_| \___/|_| |_| |_| |_|
mporm is an ORM tool written in Python with only the fundamental CRUD API for MySQL(5.5+) 简体中文
uuid
as field id
created_at
and updated_at
pip3 install mporm
from mporm import ORM, DSN, Model, StrField, IntField
ORM.load(DSN(user="xxxx", password="xxxx"))
class Hero(Model):
name = StrField()
age = IntField()
Hero.create()
# CRUD
Hero.add(name="Thor", age=1000)
Hero.where(name="Thor").set(age=1001).update()
Hero.where(name="Thor").find()
Hero.where(name="Thor").delete()
Hero.drop()
mporm can only connect MySQL database, and has two different ways to load configs of database
The minimum code that loads by dsn is wriiten as
from mporm import ORM, DSN
ORM.load(DSN(user="xxxx", password="xxxx"))
Because mporm will automatically set other configs as host
= "localhost", port
= 3306, database
= "test", charset
= "utf8"
Of course you can fill all the configs by yourself
You can write all the configs in a toml file like
[database]
user = "xxxx"
password = "xxxx"
host = "xxxx"
port = 3306
database = "xxxx"
charset = "xxxx"
Then use load_file
method
from mporm import ORM
ORM.load_file("path/to/toml")
Note that if you use the second way, remember all the 6 configs needs to be written in the toml file.
You can define a model with an attribute __prefix__
, for example:
from mporm import Model
class Hero(Model):
__prefix__ = "Marvel"
...
Hero.create()
This will create a new table named "marvel_hero"
We have defined a model like
class Hero(Model):
__prefix__ = "Marvel"
name = StrField()
age = IntField()
There are two methods you can choose from:
Hero.new(name="Thor", age=1000).insert()
or simply use
Hero.add(name="Thor", age=1000)
The SQL statement that'll be executed is
insert into `marvel_hero` (name, age) values ('Thor', 1000);
Hero.first()
## select * from `marvel_hero` order by created_at limit 1;
Hero.last()
## select * from `marvel_hero` order by created_at desc limit 1;
Hero.take()
## select * from `marvel_hero` limit 1;
Plus they can take an argument
Hero.first(10)
## select * from `marvel_hero` order by created_at limit 10;
Hero.last(10)
## select * from `marvel_hero` order by created_at desc limit 10;
Hero.take(10)
## select * from `marvel_hero` limit 10;
Hero.where(name="Thor", age=1000).find()
## select * from `marvel_hero` where name = 'Thor' and age = 1000;
Hero.where(name="Thor", age=1000).findone()
## select * from `marvel_hero` where name = 'Thor' and age = 1000 limit 1;
Of course, Specified Fields Selecting is available
Hero.where(name="Thor", age=1000).select("name").find()
## select name from `marvel_hero` where name = 'Thor' and age = 1000;
Or you can simply use
Hero.where(name="Thor", age=1000).filter("name")
## select name from `marvel_hero` where name = 'Thor' and age = 1000;
Hero.where(name="Thor").count()
## select count(id) from `marvel_hero` where name = 'Thor';
Also custom count field is available
Hero.where(name="Thor").count("age")
## select count(age) from `marvel_hero` where name = 'Thor';
Hero.where(name="Thor").order("age", desc=True).find()
## select * from `marvel_hero` where name = 'Thor' order by age desc;
Hero.where(name="Thor").limit(10).find()
## select * from `marvel_hero` where name = 'Thor' limit 10;
Hero.where(name="Thor").offset(10).find()
## select * from `marvel_hero` where name = 'Thor' offset 10;
Of course, you can use them like chains
Hero.where(name="Thor").order("age").limit(10).offset(10).select("name", "age").find()
## select name, age from `marvel_hero` where name = 'Thor' order by age asc limit 10 offset 10;
Hero.where(name="Thor").set(age=1001).update()
## update `marvel_hero` set age=1001 where name = 'Thor';
Hero.where(name="Thor").delete()
## delete from `marvel_hero` where name = "Thor";
Note that the methods insert()
update()
delete()
return the amount of rows that're affected and method find()
returns a list-typed
query result and not to mention, the method findone()
returns a dict-typed
query result.
where-like
where-or
Where-<>
custom sql statement execution
You can do anything to help deliver a better MPORM.
@ XJJ, 2019~datetime.now()
Released under the MIT License
FAQs
MySQL ORM in Python
We found that mporm demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.