Skip to main content

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 insert method.
  • Retrieve documents using query method.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snailDB-0.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snailDB-0.0.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file snailDB-0.0.1.tar.gz.

File metadata

  • Download URL: snailDB-0.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for snailDB-0.0.1.tar.gz
Algorithm Hash digest
SHA256 dcc427f1e75f4cd09b9f4ace407e5bfaf100b44a1a51f50d2ccba862898bbdbd
MD5 aa36750b3111c589d296ba94c3e36c14
BLAKE2b-256 ffa9c314c5c5112e3d30f3984adbd0758f0a7d6784a92b381fdddd289496b5be

See more details on using hashes here.

File details

Details for the file snailDB-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: snailDB-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for snailDB-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10ec1186625071a852512a43e1376c3eca8947906ec26733bbd4d4d6ca992e4a
MD5 87640fa996e18c50015f734b80c511aa
BLAKE2b-256 07529233eee151f99c0fd546268bca5e2d3d999fed67a17922608d285717e3f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page