SnailDB is a lightweight, non-SQL database for Python, designed for simplicity and ease of use
Project description
# SnailDB
SnailDB is a lightweight, non-SQL database for Python, designed for simplicity and ease of use.
## Table of Contents
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Features](#features)
- [Examples](#examples)
- [Contributing](#contributing)
- [License](#license)
## Installation
```bash
pip install snailDB
Quick Start
from snaildb import SnailDB
# Create a SnailDB instance
db = SnailDB('my_database.json')
# Insert a document
document = {'_id': 1, 'name': 'John Doe'}
db.insert(document)
# Query documents
result = db.query(lambda doc: doc['name'] == 'John Doe')
print(result)
Features
1. Insertion and Retrieval
- Insert a document with
insertmethod. - Retrieve documents using
querymethod.
2. Query Optimization
- Indexing: Implement indexing for frequently queried fields.
- Caching: Cache query results for frequently used queries.
- Optimization: Analyze and optimize query execution plans.
3. Batch Operations
- Batch insert multiple documents for improved efficiency.
4. Transaction Support
- Start, commit, and rollback transactions for atomic operations.
5. Documentation and Query Optimization
- Add comprehensive documentation for all features.
- Optimize queries and operations for better performance.
Examples
Examples: Inserting
# Examples 1: Insert a document
document1 = {"_id": "1", "name": "Alice", "age": 30, "city": "Wonderland"}
document_id = db.insert(document1)
print(f"\nDocument ID after insertion: {document_id}")
# Examples 2: Insert a document without id
document1 = {"name": "Alice", "age": 30, "city": "Wonderland"}
document_id = db.insert(document1)
print(f"\nDocument ID after insertion: {document_id}")
# Examples 3: Insert multiple documents
documents_to_insert = [
{"name": "Bob", "age": 25, "city": "Dreamland"},
{"name": "Charlie", "age": 28, "city": "Fantasyville"},
]
documents_ids = db.insert_multiple(documents_to_insert)
print("\nDocument IDs after multiple insertions:", documents_ids)
Examples: Get all documents in the default table
all_documents = db.get_all()
print("\nAll Documents:")
print(all_documents)
# Example 4: Find documents based on a query
query = {"city": "Wonderland"}
found_documents = db.find(query)
print("\nFound Documents:")
print(found_documents)
# Example 5: Update documents based on a query
update_query = {"name": "Alice"}
update_fields = {"age": 31, "city": "Updated Wonderland"}
db.update(update_query, update_fields)
updated_document = db.find(update_query)[0]
print("\nUpdated Document:")
print(updated_document)
# Example 6: Remove documents based on a query
remove_query = {"name": "Bob"}
db.remove(remove_query)
print("\nDocuments after removal:")
print(db.get_all())
Examples: Create an index for faster querying
# Examples 7: Create an index for faster querying
index_fields = ["name", "city"]
db.create_index("name_city_index", index_fields)
Examples: Find documents using an index
# Examples 8: Find documents using an index
index_query_values = ["Alice", "Updated Wonderland"]
found_with_index = db.find_with_index("name_city_index", index_query_values)
print("\nFound with Index:")
print(found_with_index)
# Example 9: Remove an index
db.remove_index("name_city_index")
# Example 10: Remove all
db.remove_all()
print("\nDocuments after removing all:")
print(db.get_all())
Query documents
# Example 11: Query documents
result = db.query(lambda doc: doc['name'] == 'Alice')
print(result)
### Example 12: Indexing and Querying with Index
# Create an index for a field in a table
db.create_index('my_table', 'my_field')
# Query using the index
result = db.query_with_index('my_table', 'my_field', 'desired_value')
print(result)
For more examples and detailed usage, refer to the Examples document.
Contributing
Contributions are welcome! If you'd like to contribute to SnailDB, please check the Contributing Guide.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snailDB-0.0.2.tar.gz.
File metadata
- Download URL: snailDB-0.0.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0caea67e633ebb7f56fade5d59bdcd6f22c7a9f6992136f3ea206d9cebd191e0
|
|
| MD5 |
bfe00243b30f43d448b93a87a99df0fc
|
|
| BLAKE2b-256 |
67cfe857b70103b1d2cf63afac4c7e52d6e47209b05d6495ab45781a33214d77
|
File details
Details for the file snailDB-0.0.2-py3-none-any.whl.
File metadata
- Download URL: snailDB-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b666e7eee4e0f2d84c59107feebc42419e7b3713092f0dbc19d95b2d6deba329
|
|
| MD5 |
1803ad645f180f19f72ba34d08097838
|
|
| BLAKE2b-256 |
294e80ef3406e42f7c895c6bbf2337529e15bc268af89c693ae8192bf9eff469
|