Skip to content

Commit

Permalink
fixed the README formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
patx committed Jan 2, 2025
1 parent 68d5a8d commit 6be6c6d
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,90 @@ kenobiDB is a small document based database (abstraction) supporting very simple
* For the latest version just copy and paste the `kenobi.py` file into your working directory.

## kenobiDB is fun!
```
>>> from kenobi import KenobiDB
>>> from kenobi import KenobiDB
>>> db = KenobiDB('example.db')
>>> db = KenobiDB('example.db')
>>> db.insert({'name': 'Obi-Wan', 'color': 'blue'})
True
>>> db.insert({'name': 'Obi-Wan', 'color': 'blue'})
True

>>> db.search('color', 'blue')
[{'name': 'Obi-Wan', 'color': 'blue'}]
>>> db.search('color', 'blue')
[{'name': 'Obi-Wan', 'color': 'blue'}]
```

# Overview/Usage

## Initialization and Setup:
* The database is initialized with a specified file. If the file does not exist, it is created. SQLite is used for storage, and the database ensures the necessary table and indices are created.
db = KenobiDB('example.db')
```
db = KenobiDB('example.db')
```

## Concurrency:
* The class uses `RLock` for thread safety.
* A `ThreadPoolExecutor` with a maximum of 5 workers is used to handle concurrent operations.
* The `execute_async` method allows for asynchronous execution of functions using the thread pool.
future = db.execute_async(insert_document, db, document)
```
future = db.execute_async(insert_document, db, document)
```

## Basic Operations:
* Insert: Add a single document or multiple documents to the database.
db.insert({'name': 'Obi-Wan', 'color': 'blue'})
db.insert_many([{'name': 'Anakin', 'color': 'red'}, {'name': 'Yoda', 'color': 'green'}])
```
db.insert({'name': 'Obi-Wan', 'color': 'blue'})
db.insert_many([{'name': 'Anakin', 'color': 'red'}, {'name': 'Yoda', 'color': 'green'}])
```

* Remove: Remove documents matching a specific key-value pair.
db.remove('name', 'Obi-Wan')
```
db.remove('name', 'Obi-Wan')
```

* Update: Update documents matching a specific key-value pair with new data.
db.update('name', 'Anakin', {'color': 'dark'})
```
db.update('name', 'Anakin', {'color': 'dark'})
```

* Purge: Remove all documents from the database.
db.purge()
```
db.purge()
```

## Search Operations:
* All: Retrieve all documents with optional pagination.
db.all(limit=10, offset=0)
db.all() # No pagination
````
db.all(limit=10, offset=0)
db.all() # No pagination
```
* Search: Retrieve documents matching a specific key-value pair with optional pagination.
db.search('color', 'blue')
```
db.search('color', 'blue')
```
* Find Any: Retrieve documents where a key matches any value in a list.
db.find_any('color', ['blue', 'red'])
```
db.find_any('color', ['blue', 'red'])
```
* Find All: Retrieve documents where a key matches all values in a list.
db.find_all('color', ['blue', 'red'])
```
db.find_all('color', ['blue', 'red'])
```
## Asynchronous Execution:
* The `execute_async` method allows for asynchronous execution of functions using the thread pool.
def insert_document(db, document):
db.insert(document)
future = db.execute_async(insert_document, db, {'name': 'Luke', 'color': 'green'})
```
def insert_document(db, document):
db.insert(document)
future = db.execute_async(insert_document, db, {'name': 'Luke', 'color': 'green'})
```
## Thread Pool Management:
* The `close` method shuts down the thread pool executor.
db.close()
```
db.close()
```

0 comments on commit 6be6c6d

Please sign in to comment.