https://github.com/ahmednooor/peanutdb
🥜 A JSON based database for quick prototyping and playing.
https://github.com/ahmednooor/peanutdb
database json python
Last synced: 6 months ago
JSON representation
🥜 A JSON based database for quick prototyping and playing.
- Host: GitHub
- URL: https://github.com/ahmednooor/peanutdb
- Owner: ahmednooor
- License: mit
- Archived: true
- Created: 2018-01-12T11:18:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-24T07:54:49.000Z (over 8 years ago)
- Last Synced: 2024-10-10T09:26:58.428Z (over 1 year ago)
- Topics: database, json, python
- Language: Python
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.md
Awesome Lists containing this project
README
🥜 peanutdb
============
A JSON based database for quick prototyping and playing.
.. image:: https://img.shields.io/badge/pypi-v0.2.0-yellow.svg?style=flat-square
:target: https://pypi.python.org/pypi/peanutdb
Installation
------------
.. code-block:: bash
$ pip install peanutdb
Or clone the repo:
.. code-block:: bash
$ git clone https://github.com/ahmednooor/peanutdb.git
and copy `peanutdb` directory in you project directory.
Usage
-----
.. code-block:: python
from peanutdb import PeanutDB
db = PeanutDB("path/to/db.json")
# or db = PeanutDB() for in-memory
db.create_table(
table_name="Users",
schema={
"username": {"type": "text", "unique": True, "notnull": True},
"name": {"type": "text", "unique": False, "notnull": True}
}
)
# "__ID" field is automatically added to schema as primary key
# like so, "__ID": {"type": "text", "unique": True, "notnull": True}
# Data Types: "text", "number", "boolean", "list", "dict", "any"
# or you can create a table without any schema like so,
db.create_table(
table_name="Table_Name"
)
db.insert(
table_name="Users",
fields={
"username": "john",
"name": "John Doe"
}
)
# "__ID" field is automatically inserted as primary key using `uuid.uuid4()`
result = db.select(
table_name="Users",
where={
"username": "john"
}
)
print(result)
# result will always be a list of dicts even if there is only one matched item
# you can select all items from a table like so,
result = db.select(
table_name="Users"
)
db.update(
table_name="Users",
fields={
"name": "Johnathon Doe"
},
where={
"username": "john"
}
)
db.delete(
table_name="Users",
where={
"username": "john"
}
)
db.delete_table(
table_name="Users"
)
# in case of error or failure, `None` is returned.
Meta
----
Source: https://github.com/ahmednooor/peanutdb
Author: Ahmed Noor
License: MIT