electrodb


Nameelectrodb JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/E491K8/electrodb
SummaryThis project provides a reliable database, allowing you to perform CRUD operations and more on collections of documents.
upload_time2023-08-14 11:47:26
maintainer
docs_urlNone
authorPawan kumar
requires_python>=3.6
license
keywords your keywords here
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ElectroDB Database

This project provides a reliable database, allowing you to perform CRUD operations and more on collections of documents.

## Features

- Insert single and multiple documents
- Update documents using various operators
- Delete documents based on filters
- Find documents based on filters
- Fetch all documents or with a specified query
- Count documents that match a query
- Retrieve distinct values of a field
- Drop indexes
- Find and update a single document
- Find and replace a single document
- Find and delete a single document
- Perform bulk write operations
- List collections, indexes, and collection names
- Replace documents based on filters
- Rename a collection
- Estimate document count
- Sort documents based on a field
- Aggregate documents using a pipeline
- Create an index on a field
- Drop a collection
- Find or insert a document using upsert
- Retrieve distinct values of a field with a query
- Perform map-reduce operations
- Find documents by email
- Validate data based on a query
- Check if a collection is capped
- Compact the database by removing deleted documents

## Usage

```python

from electrodb import Electron

client = Electron(host='localhost', port=37017, username='root', password='root')
db = client['my_database']
collection = db['users']

# Insert one document
insert_result = collection.insert_one({"name": "Alice", "age": 30})
print(insert_result)

# Insert multiple documents
insert_many_result = collection.insert_many([
    {"name": "Bob", "age": 25},
    {"name": "Charlie", "age": 28}
])
print(insert_many_result)

# Update a document
update_result = collection.update_one({"name": "Alice"}, {"$set": {"age": 31}})
print(update_result)

# Update multiple documents
update_many_result = collection.update_many({"age": {"$lt": 30}}, {"$set": {"status": "young"}})
print(update_many_result)

# Delete a document
delete_result = collection.delete_one({"name": "Bob"})
print(delete_result)

# Delete multiple documents
delete_many_result = collection.delete_many({"age": {"$lt": 30}})
print(delete_many_result)

# Find documents using a query
query = {"status": "young"}
found_documents = collection.fetch_all(query)
print(found_documents)

# Count documents matching a query
count = collection.count_documents(query)
print(count)

# Get distinct values for a field
distinct_values = collection.distinct("age", query)
print(distinct_values)

# Create an index
index_result = collection.create_index("age")
print(index_result)

# List collection names
collection_names = collection.list_collection_names()
print(collection_names)

# Drop a collection
drop_result = collection.drop()
print(drop_result)

# Find one document and upsert
upsert_result = collection.find_one_and_upsert({"name": "David"}, {"name": "David", "age": 22})
print(upsert_result)

# Validate data based on a query
validate_query = {"age": 30}
validated_data = collection.validate_data(validate_query)
print(validated_data)

# Check if collection is capped
is_capped = collection.is_capped()
print(is_capped)

# Compact the database
compact_result = collection.compact_database()
print(compact_result)

# List collections in the database
collection_list = collection.list_collections()
print(collection_list)

# List indexes in the collection
index_list = collection.list_indexes()
print(index_list)

# Rename the collection
rename_result = collection.rename_collection("new_collection_name")
print(rename_result)

# Get estimated document count
document_count = collection.estimated_document_count()
print(document_count)

# Sort documents by a field
sorted_documents = collection.sort("age", reverse=True)
print(sorted_documents)

# Aggregate documents using a pipeline
pipeline = [
    {"$sort": {"field": "age", "order": 1}},
    {"$project": ["name", "age"]}
]
aggregated_result = collection.aggregate(pipeline)
print(aggregated_result)

# Find one document and replace
replace_result = collection.find_one_and_replace({"name": "David"}, {"name": "Ella", "age": 27})
print(replace_result)

# Find one document and delete
delete_result = collection.find_one_and_delete({"name": "Ella"})
print(delete_result)

# Perform map-reduce operation
def map_function(item):
    return {"age": item["age"]}

def reduce_function(key, values):
    return sum(values) / len(values)

map_reduce_result = collection.map_reduce(map_function, reduce_function)
print(map_reduce_result)

# Find documents by email
email_search_result = collection.find_by_email("alice@example.com")
print(email_search_result)

# Distinct values with a query
distinct_query_result = collection.distinct_with_query("age", {"status": "young"})
print(distinct_query_result)

# Drop an index
drop_index_result = collection.drop_index("age_1")
print(drop_index_result)

# Define bulk write operations
bulk_operations = [
    {"insert_one": {"name": "Alice", "email": "alice@example.com", "age": 25}},
    {"insert_many": [
        {"name": "Bob", "email": "bob@example.com", "age": 30},
        {"name": "Charlie", "email": "charlie@example.com", "age": 28}
    ]},
    {"update_one": {"filter": {"age": {"$gt": 25}}, "update": {"$set": {"status": "senior"}}}},
    {"update_many": {"filter": {"age": {"$lt": 30}}, "update": {"$set": {"status": "young"}}}},
    {"delete_one": {"age": {"$gt": 25}}},
    {"delete_many": {"age": {"$lt": 30}}}
]

# Use the bulk_write function to perform the defined operations
result = collection.bulk_write(bulk_operations)

```

# Recovery

```python

from electrodb import Recovery, Electron

client = Electron(host='localhost', port=37017, username='root', password='root')
db = client['my_database']
collection = db['users']
# Create a recovery instance
recovery = Recovery(client)

# Backup a database
backup_result = recovery.backup('my_database', format='zip')
print(backup_result)  # Backup of 'my_database' created at '/path/to/backup/my_database.zip'.

# Restore a database
restore_result = recovery.restore('/path/to/backup/my_database.zip', format='zip')
print(restore_result)  # Database restored from 'zip' backup.


```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/E491K8/electrodb",
    "name": "electrodb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "your,keywords,here",
    "author": "Pawan kumar",
    "author_email": "confict.con@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/68/e1/e64fe368dc41c1df758fafa809188d4c1a8bb7fa7edff5d70a56dbd34e4b/electrodb-1.0.1.tar.gz",
    "platform": null,
    "description": "# ElectroDB Database\r\n\r\nThis project provides a reliable database, allowing you to perform CRUD operations and more on collections of documents.\r\n\r\n## Features\r\n\r\n- Insert single and multiple documents\r\n- Update documents using various operators\r\n- Delete documents based on filters\r\n- Find documents based on filters\r\n- Fetch all documents or with a specified query\r\n- Count documents that match a query\r\n- Retrieve distinct values of a field\r\n- Drop indexes\r\n- Find and update a single document\r\n- Find and replace a single document\r\n- Find and delete a single document\r\n- Perform bulk write operations\r\n- List collections, indexes, and collection names\r\n- Replace documents based on filters\r\n- Rename a collection\r\n- Estimate document count\r\n- Sort documents based on a field\r\n- Aggregate documents using a pipeline\r\n- Create an index on a field\r\n- Drop a collection\r\n- Find or insert a document using upsert\r\n- Retrieve distinct values of a field with a query\r\n- Perform map-reduce operations\r\n- Find documents by email\r\n- Validate data based on a query\r\n- Check if a collection is capped\r\n- Compact the database by removing deleted documents\r\n\r\n## Usage\r\n\r\n```python\r\n\r\nfrom electrodb import Electron\r\n\r\nclient = Electron(host='localhost', port=37017, username='root', password='root')\r\ndb = client['my_database']\r\ncollection = db['users']\r\n\r\n# Insert one document\r\ninsert_result = collection.insert_one({\"name\": \"Alice\", \"age\": 30})\r\nprint(insert_result)\r\n\r\n# Insert multiple documents\r\ninsert_many_result = collection.insert_many([\r\n    {\"name\": \"Bob\", \"age\": 25},\r\n    {\"name\": \"Charlie\", \"age\": 28}\r\n])\r\nprint(insert_many_result)\r\n\r\n# Update a document\r\nupdate_result = collection.update_one({\"name\": \"Alice\"}, {\"$set\": {\"age\": 31}})\r\nprint(update_result)\r\n\r\n# Update multiple documents\r\nupdate_many_result = collection.update_many({\"age\": {\"$lt\": 30}}, {\"$set\": {\"status\": \"young\"}})\r\nprint(update_many_result)\r\n\r\n# Delete a document\r\ndelete_result = collection.delete_one({\"name\": \"Bob\"})\r\nprint(delete_result)\r\n\r\n# Delete multiple documents\r\ndelete_many_result = collection.delete_many({\"age\": {\"$lt\": 30}})\r\nprint(delete_many_result)\r\n\r\n# Find documents using a query\r\nquery = {\"status\": \"young\"}\r\nfound_documents = collection.fetch_all(query)\r\nprint(found_documents)\r\n\r\n# Count documents matching a query\r\ncount = collection.count_documents(query)\r\nprint(count)\r\n\r\n# Get distinct values for a field\r\ndistinct_values = collection.distinct(\"age\", query)\r\nprint(distinct_values)\r\n\r\n# Create an index\r\nindex_result = collection.create_index(\"age\")\r\nprint(index_result)\r\n\r\n# List collection names\r\ncollection_names = collection.list_collection_names()\r\nprint(collection_names)\r\n\r\n# Drop a collection\r\ndrop_result = collection.drop()\r\nprint(drop_result)\r\n\r\n# Find one document and upsert\r\nupsert_result = collection.find_one_and_upsert({\"name\": \"David\"}, {\"name\": \"David\", \"age\": 22})\r\nprint(upsert_result)\r\n\r\n# Validate data based on a query\r\nvalidate_query = {\"age\": 30}\r\nvalidated_data = collection.validate_data(validate_query)\r\nprint(validated_data)\r\n\r\n# Check if collection is capped\r\nis_capped = collection.is_capped()\r\nprint(is_capped)\r\n\r\n# Compact the database\r\ncompact_result = collection.compact_database()\r\nprint(compact_result)\r\n\r\n# List collections in the database\r\ncollection_list = collection.list_collections()\r\nprint(collection_list)\r\n\r\n# List indexes in the collection\r\nindex_list = collection.list_indexes()\r\nprint(index_list)\r\n\r\n# Rename the collection\r\nrename_result = collection.rename_collection(\"new_collection_name\")\r\nprint(rename_result)\r\n\r\n# Get estimated document count\r\ndocument_count = collection.estimated_document_count()\r\nprint(document_count)\r\n\r\n# Sort documents by a field\r\nsorted_documents = collection.sort(\"age\", reverse=True)\r\nprint(sorted_documents)\r\n\r\n# Aggregate documents using a pipeline\r\npipeline = [\r\n    {\"$sort\": {\"field\": \"age\", \"order\": 1}},\r\n    {\"$project\": [\"name\", \"age\"]}\r\n]\r\naggregated_result = collection.aggregate(pipeline)\r\nprint(aggregated_result)\r\n\r\n# Find one document and replace\r\nreplace_result = collection.find_one_and_replace({\"name\": \"David\"}, {\"name\": \"Ella\", \"age\": 27})\r\nprint(replace_result)\r\n\r\n# Find one document and delete\r\ndelete_result = collection.find_one_and_delete({\"name\": \"Ella\"})\r\nprint(delete_result)\r\n\r\n# Perform map-reduce operation\r\ndef map_function(item):\r\n    return {\"age\": item[\"age\"]}\r\n\r\ndef reduce_function(key, values):\r\n    return sum(values) / len(values)\r\n\r\nmap_reduce_result = collection.map_reduce(map_function, reduce_function)\r\nprint(map_reduce_result)\r\n\r\n# Find documents by email\r\nemail_search_result = collection.find_by_email(\"alice@example.com\")\r\nprint(email_search_result)\r\n\r\n# Distinct values with a query\r\ndistinct_query_result = collection.distinct_with_query(\"age\", {\"status\": \"young\"})\r\nprint(distinct_query_result)\r\n\r\n# Drop an index\r\ndrop_index_result = collection.drop_index(\"age_1\")\r\nprint(drop_index_result)\r\n\r\n# Define bulk write operations\r\nbulk_operations = [\r\n    {\"insert_one\": {\"name\": \"Alice\", \"email\": \"alice@example.com\", \"age\": 25}},\r\n    {\"insert_many\": [\r\n        {\"name\": \"Bob\", \"email\": \"bob@example.com\", \"age\": 30},\r\n        {\"name\": \"Charlie\", \"email\": \"charlie@example.com\", \"age\": 28}\r\n    ]},\r\n    {\"update_one\": {\"filter\": {\"age\": {\"$gt\": 25}}, \"update\": {\"$set\": {\"status\": \"senior\"}}}},\r\n    {\"update_many\": {\"filter\": {\"age\": {\"$lt\": 30}}, \"update\": {\"$set\": {\"status\": \"young\"}}}},\r\n    {\"delete_one\": {\"age\": {\"$gt\": 25}}},\r\n    {\"delete_many\": {\"age\": {\"$lt\": 30}}}\r\n]\r\n\r\n# Use the bulk_write function to perform the defined operations\r\nresult = collection.bulk_write(bulk_operations)\r\n\r\n```\r\n\r\n# Recovery\r\n\r\n```python\r\n\r\nfrom electrodb import Recovery, Electron\r\n\r\nclient = Electron(host='localhost', port=37017, username='root', password='root')\r\ndb = client['my_database']\r\ncollection = db['users']\r\n# Create a recovery instance\r\nrecovery = Recovery(client)\r\n\r\n# Backup a database\r\nbackup_result = recovery.backup('my_database', format='zip')\r\nprint(backup_result)  # Backup of 'my_database' created at '/path/to/backup/my_database.zip'.\r\n\r\n# Restore a database\r\nrestore_result = recovery.restore('/path/to/backup/my_database.zip', format='zip')\r\nprint(restore_result)  # Database restored from 'zip' backup.\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "This project provides a reliable database, allowing you to perform CRUD operations and more on collections of documents.",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/E491K8/electrodb"
    },
    "split_keywords": [
        "your",
        "keywords",
        "here"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0b3e28c4046d475143c093b1433c9e829267e7fb2b8f08a0038daf10aa811833",
                "md5": "eb1594cdd39c54f7fe7c5bebe30c2019",
                "sha256": "c8d3866e45e2c19dd51f19622cfefed1de7f33aa5bc01bd52e991988ebc40f08"
            },
            "downloads": -1,
            "filename": "electrodb-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb1594cdd39c54f7fe7c5bebe30c2019",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 11593,
            "upload_time": "2023-08-14T11:47:24",
            "upload_time_iso_8601": "2023-08-14T11:47:24.077566Z",
            "url": "https://files.pythonhosted.org/packages/0b/3e/28c4046d475143c093b1433c9e829267e7fb2b8f08a0038daf10aa811833/electrodb-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "68e1e64fe368dc41c1df758fafa809188d4c1a8bb7fa7edff5d70a56dbd34e4b",
                "md5": "3f16a44571182409060e431617544204",
                "sha256": "ab81f120b5e4c0d8eae76a6abb654cce6212d42ce8002d37216513892998ee8b"
            },
            "downloads": -1,
            "filename": "electrodb-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3f16a44571182409060e431617544204",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 13398,
            "upload_time": "2023-08-14T11:47:26",
            "upload_time_iso_8601": "2023-08-14T11:47:26.345119Z",
            "url": "https://files.pythonhosted.org/packages/68/e1/e64fe368dc41c1df758fafa809188d4c1a8bb7fa7edff5d70a56dbd34e4b/electrodb-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-14 11:47:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "E491K8",
    "github_project": "electrodb",
    "github_not_found": true,
    "lcname": "electrodb"
}
        
Elapsed time: 0.10266s