Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberkutti-iedc authored Nov 19, 2023
1 parent 5817c1c commit 1c3ac88
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 110 deletions.
90 changes: 83 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,94 @@ print(result)

## Examples

### Example 1: Inserting and Querying
### Examples: Inserting
```python
# Insert a document
document = {'_id': 1, 'name': 'Alice'}
db.insert(document)
# 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
```python

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
```python
# 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
```python
# 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
```python
# Example 11: Query documents
result = db.query(lambda doc: doc['name'] == 'Alice')
print(result)
```

### Example 2: Indexing and Querying with Index
```python

### Example 12: Indexing and Querying with Index

# Create an index for a field in a table
db.create_index('my_table', 'my_field')

Expand All @@ -91,3 +166,4 @@ Contributions are welcome! If you'd like to contribute to SnailDB, please check
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
```
Feel free to customize the content further based on your specific project details and preferences.
4 changes: 2 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ By participating in this project, you agree to abide by our [Code of Conduct](CO

### Reporting Bugs

If you find a bug, please ensure that it hasn't been reported before. You can check the existing issues on the [GitHub issues page](https://github.com/your-username/snaildb/issues). If the bug is not reported, please open a new issue with a clear and detailed description of the problem, along with steps to reproduce it.
If you find a bug, please ensure that it hasn't been reported before. You can check the existing issues on the [GitHub issues page](https://github.com/cyberkutti-iedc/snailDB/issues). If the bug is not reported, please open a new issue with a clear and detailed description of the problem, along with steps to reproduce it.

### Requesting Features

Expand All @@ -34,7 +34,7 @@ We'll review your changes and provide feedback. Once everything is ready, your p

To set up a development environment:

1. Clone the repository: `git clone https://github.com/your-username/snaildb.git`
1. Clone the repository: `git clone https://github.com/cyberkutti-iedc/snailDB.git`
2. Navigate to the project directory: `cd snaildb`
3. Create a virtual environment: `python -m venv venv`
4. Activate the virtual environment:
Expand Down
132 changes: 63 additions & 69 deletions examples/example_usage.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,65 @@
from snaildb import SnailDB


# Create a SnailDB instance
#db = SnailDB('snaildb.json')
#db.insert({'name': 'Sreeraj', 'age': 25, 'city': 'New York'})
# Insert a document
#document_id = db.insert({'name': 'John', 'age': 25, 'city': 'New York'})
#print("Inserted Document ID:", document_id)

# Get all documents
#all_documents = db.get_all()
#print("All Documents:", all_documents)

# Query documents
#query_result = db.find({'name': 'John'})
#print("Query Result:", query_result)

# Update documents
#db.update({'name': 'John'}, {'age': 26})

# Remove documents based on a query
#db.remove({'name': 'John'})

# Remove all documents
#db.remove_all()

# Create a new query object
#query_func = db.create_query('age', '>', 30)
#filtered_documents = [doc for doc in db.get_all() if query_func(doc)]
#print("Filtered Documents:", filtered_documents)

# Match any document with a key field value equal to 2
#match_result = db.match_any([('age', '==', 2)])
#print("Match Result:", match_result)



# Example Usage
#from snaildb import SnailDB
if __name__ == "__main__":
db = SnailDB('snaildb.json')

# Insert a document
db.insert({'name': 'test', 'age': 25, 'city': 'New York'})

# Get all documents
all_documents = db.get_all()
print("All Documents:", all_documents)

# Query documents
#query_result = db.find({'name': 'John'})
#print("Query Result:", query_result)

# Update documents
db.update({'name': 'John'}, {'age': 26})

# Remove documents based on a query
db.remove({'name': 'John'})

# Remove all documents
#db.remove()

# Create a new query object
# query_func = db.create_query('age', '>', 30)
#filtered_documents = [doc for doc in db.get_all() if query_func(doc)]
#print("Filtered Documents:", filtered_documents)

# Match any document with a key field value equal to 2
#match_result = db.match_any([('age', '==', 2)])
#print("Match Result:", match_result)
db = SnailDB("example_db.json")
# Example 0: 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}")

# Example 1: 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}")


# Example 2: 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)
# Example 3: 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())


# Example 7: Create an index for faster querying
index_fields = ["name", "city"]
db.create_index("name_city_index", index_fields)


# Example 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())
17 changes: 13 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
long_description = f.read()

setup(
name='snaildb',
name='snailDB',
version='0.0.1',
author='SREERAJ V RAJESH',
author_email='cyberkutti@gmail.com',
description='A simple non-SQL database like TinyDB or MongoDB using Python',
description='SnailDB is a lightweight, non-SQL database for Python, designed for simplicity and ease of use',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/cyberkutti-iedc/snaildb',
url='https://github.com/cyberkutti-iedc/snailDB',
packages=find_packages(),
install_requires=[
# List your dependencies here
'fastjsonschema',
'ujson',
'orjson',
'jsonschema',
'fastjsonschema',
'pathspec',
'repath',
'typing_extensions',
'Flask',
'Flask-SocketIO'
],
entry_points={
'console_scripts': [
Expand Down
Loading

0 comments on commit 1c3ac88

Please sign in to comment.