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.
abarorm is a lightweight and easy-to-use Object-Relational Mapping (ORM) library for SQLite & PostgreSQL and MySQL databases in Python. It aims to provide a simple and intuitive interface for managing database models and interactions.
abarorm is a lightweight and easy-to-use Object-Relational Mapping (ORM) library for SQLite, MySQL, and PostgreSQL databases in Python. It provides a simple and intuitive interface for managing database models and interactions. |
---|
create_table()
calls.all()
method.filter
method now supports order_by
functionality for result ordering.__gte
and __lte
functionality in the filter section.You can install abarorm from PyPI using pip:
pip install abarorm
For MySQL support, you also need to install mysql-connector-python
:
pip install mysql-connector-python
For PostgreSQL support, you need to install psycopg2-binary
:
pip install psycopg2-binary
For detailed documentation, examples, and advanced usage, please visit the official abarorm documentation website.
Before defining models, you need to set up your database configuration. This involves specifying connection parameters for the database you are using (SQLite, MySQL, or PostgreSQL). Here’s an example of how to configure the database:
# Database configuration
DATABASE_CONFIG = {
'sqlite': {
'db_name': 'example.db', # Name of the SQLite database file
},
'mysql': {
'host': 'localhost',
'user': 'your_mysql_user',
'password': 'your_mysql_password',
'database': 'example_db',
},
'postgresql': {
'host': 'localhost',
'user': 'your_pg_user',
'password': 'your_pg_password',
'database': 'example_db',
}
}
After setting up the database configuration, you can define your models. A model is a representation of a database table. Here’s how to create a model using abarorm:
from abarorm import SQLiteModel, MySQLModel, PostgreSQLModel
from abarorm.fields import CharField, DateTimeField, ForeignKey
# Define the Category model for SQLite
class Category(SQLiteModel):
class Meta:
db_config = DATABASE_CONFIG['sqlite']
table_name = 'categories' # Name of the table for storing the Category model data
title = CharField(max_length=200, null=False) # Title of the category, must be unique and not null
create_time = DateTimeField(auto_now=True, auto_now_add=True) # Automatically set to current datetime
update_time = DateTimeField(auto_now=True) # Automatically set to current datetime
# Define the Post model for MySQL
class Post(MySQLModel):
class Meta:
db_config = DATABASE_CONFIG['mysql']
title = CharField(max_length=100, null=False) # Title of the post, must be unique and not null
create_time = DateTimeField(auto_now=True) # Automatically set to current datetime
category = ForeignKey(to=Category) # Foreign key referring to the Category model
Now that you have defined your models, you can perform CRUD operations. Here’s a breakdown of each operation:
To create new records in the database, use the create()
method. For example:
# Create a new category
Category.create(title='Movies')
# Create a new post
category = Category.get(id=1) # Fetch the category with ID 1
if category:
Post.create(title='Godfather', category=category.id) # Create a new post associated with the fetched category
To read records from the database, use the all()
or get()
methods:
# Retrieve all posts
all_posts = Post.all()
# Retrieve a specific post by ID
post_data = Post.get(id=1)
The filter()
method allows you to retrieve records based on specified criteria. You can use keyword arguments to filter by field values and sort the results using order_by
.
# Filter posts by category ID and order by creation time
filtered_posts = Post.filter(category=category.id, order_by='-create_time')
You can also use special lookup expressions like __gte
(greater than or equal to) and __lte
(less than or equal to) for more complex queries:
# Retrieve posts created after a specific date
filtered_posts = Post.filter(create_time__gte='2024-01-01 00:00:00')
To update existing records, fetch the record, modify its attributes, and then save it:
if post_data:
post_data.title = "The Godfather"
post_data.save() # Save the updated post data
Or:
Post.update(1, title='Updated Godfather') # Update the title of the post with ID 1 to 'Updated Godfather'
To delete a record from the database, use the delete()
method:
Post.delete(1) # Delete the post with ID 1
filter
method now includes support for order_by
, allowing for more flexible queries.Important for Developers: When adding new fields to models, they will default to NULL
. It’s recommended to recreate the database schema after development is complete to ensure fields have appropriate constraints and default values.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on GitHub.
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
FAQs
abarorm is a lightweight and easy-to-use Object-Relational Mapping (ORM) library for SQLite & PostgreSQL and MySQL databases in Python. It aims to provide a simple and intuitive interface for managing database models and interactions.
We found that abarorm 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.