Skip to content

Commit ba9e7dd

Browse files
feat: version 0.0.3 released
1 parent 58a1c23 commit ba9e7dd

File tree

7 files changed

+84
-7
lines changed

7 files changed

+84
-7
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## Version 0.0.3
6+
7+
- Support for multi insert queries added
8+
- `dum_db` parameter changed to `commit` in insert queries
9+
510
## Version 0.0.2
611

712
- Added support for `schema` and `table` in `Database` class
813
- Support for logger added
914
- Support for multiple tables in a database added
1015
- Support for drop table added
11-
- Support for drop database added
1216
- Support for `select` , `insert`, `update` and `delete` queries added
1317

1418
## [Initial Release] Version 0.0.1

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 align="center"><a href="https://pypi.org/project/quickDatabase/">Quick DB ⚡ 0.0.2</a></h1>
1+
<h1 align="center"><a href="https://pypi.org/project/quickDatabase/">Quick DB ⚡ 0.0.3</a></h1>
22

33
<p align="center">
44
Light weight database for python, with a simple API and a simple file format.

docs/as_module.rst

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Use as library
2+
==============
3+
4+
```
5+
from quickdb import QuickDB
6+
```
7+
8+
Initialize the database
9+
------------------------
10+
11+
```
12+
db_object = QuickDB(db_path="quickdb.json")
13+
```
14+
15+
Create a table
16+
--------------
17+
18+
It will create a table schema with the given columns and primary key.
19+
If the table already exists, it will not create a new table.
20+
21+
```
22+
table_name = 'employee'
23+
columns = ['serial', 'name', 'age', 'city', 'country', 'email', 'phone', 'salary']
24+
primary_key = 'serial'
25+
db_object.create_table(table_name, columns, primary_key)
26+
```
27+
28+
Insert data
29+
-----------
30+
31+
It will insert the data into the table. if primary_key is already present, it will not insert the data.
32+
overwrite need to pass as True to overwrite the data.
33+
34+
```
35+
db_object.insert_into(table_name=table_name,
36+
value=[1, 'John Doe', 30, 'New York', 'USA', '[email protected]', '1234567890', 50000], commit=True)
37+
db_object.insert_into(table_name=table_name,
38+
value=[1, 'John Doe', 30, 'New York', 'USA', '[email protected]', '1234567890', 50000], commit=True, overwrite=True)
39+
db_object.dump_db() # Save the data to the file
40+
```
41+
42+
Insert multiple data
43+
--------------------
44+
45+
If you want to insert multiple data at once, you can use the below method.
46+
47+
```
48+
# insert_into_many
49+
values = [
50+
[3, 'John Doe', 30, 'New York', 'USA', '[email protected]', '1234567890', 50000],
51+
[4, 'John Doe', 30, 'New York', 'USA', 'f@gs', '1234567890', 50000]
52+
]
53+
db_object.insert_into_many(table_name=table_name, values=values, commit=True)
54+
```

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22

33
project = 'quickDB'
4-
release = '0.0.2'
4+
release = '0.0.3'
55
templates_path = ['_templates']
66
source_suffix = ".rst"
77
master_doc = "index"

quickdb/main.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def get_table_primary_key(self, table_name):
132132
""" Get the primary key of the table """
133133
return self.schema[table_name]['primary_key']
134134

135-
def insert_into(self, table_name, value, overwrite=False, dump_db=False):
135+
def insert_into(self, table_name, value, overwrite=False, commit=False):
136136
""" Set the key-value pair in the database """
137137
primary_value = value[self.schema[table_name]['primary_key_index']]
138138
columns_list = self.schema[table_name]['columns_list']
@@ -146,7 +146,26 @@ def insert_into(self, table_name, value, overwrite=False, dump_db=False):
146146
self.db["database"][table_name][primary_value] = dict(zip(columns_list, value))
147147
self.logger.info(f"Inserted {value} into {table_name}")
148148

149-
if dump_db:
149+
if commit:
150+
self.dump_db()
151+
return True
152+
153+
def insert_into_many(self, table_name, values, overwrite=False, commit=False):
154+
""" Set the key-value pair in the database """
155+
for value in values:
156+
primary_value = value[self.schema[table_name]['primary_key_index']]
157+
columns_list = self.schema[table_name]['columns_list']
158+
159+
if primary_value in self.db['database'][table_name] and not overwrite:
160+
return False
161+
162+
if len(value) != len(columns_list):
163+
return False
164+
165+
self.db["database"][table_name][primary_value] = dict(zip(columns_list, value))
166+
self.logger.info(f"Inserted {value} into {table_name}")
167+
168+
if commit:
150169
self.dump_db()
151170
return True
152171

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
colorama
1+
pandas
22
pytest
33
flake8

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="quickDatabase",
8-
version="0.0.2",
8+
version="0.0.3",
99
author="Deepak Raj",
1010
author_email="[email protected]",
1111
description="Simple python database",

0 commit comments

Comments
 (0)