shelfdb 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- usr/local/bin/shelfdb +12 -0
- usr/local/lib/python3.6/site-packages/shelfdb/__pycache__/__init__.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/shelfdb/__pycache__/server.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/shelfdb/__pycache__/shelf.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/shelfdb/__pycache__/test_shelf.cpython-36.pyc +0 -0
- {shelfdb-0.2.1 → usr/local/lib/python3.6/site-packages}/shelfdb/server.py +25 -18
- {shelfdb-0.2.1 → usr/local/lib/python3.6/site-packages}/shelfdb/shelf.py +5 -4
- {shelfdb-0.2.1 → usr/local/lib/python3.6/site-packages}/shelfdb/test_shelf.py +0 -1
- {shelfdb-0.2.1/shelfdb.egg-info → usr/local/lib/python3.6/site-packages/shelfdb-0.2.2-py3.6.egg-info}/PKG-INFO +4 -3
- usr/local/lib/python3.6/site-packages/shelfdb-0.2.2-py3.6.egg-info/requires.txt +2 -0
- shelfdb-0.2.1/LICENSE +0 -7
- shelfdb-0.2.1/MANIFEST.in +0 -2
- shelfdb-0.2.1/PKG-INFO +0 -12
- shelfdb-0.2.1/README.rst +0 -77
- shelfdb-0.2.1/setup.cfg +0 -5
- shelfdb-0.2.1/setup.py +0 -24
- shelfdb-0.2.1/shelfdb.egg-info/requires.txt +0 -1
- {shelfdb-0.2.1 → usr/local/lib/python3.6/site-packages}/shelfdb/__init__.py +0 -0
- {shelfdb-0.2.1/shelfdb.egg-info → usr/local/lib/python3.6/site-packages/shelfdb-0.2.2-py3.6.egg-info}/SOURCES.txt +0 -0
- {shelfdb-0.2.1/shelfdb.egg-info → usr/local/lib/python3.6/site-packages/shelfdb-0.2.2-py3.6.egg-info}/dependency_links.txt +0 -0
- {shelfdb-0.2.1/shelfdb.egg-info → usr/local/lib/python3.6/site-packages/shelfdb-0.2.2-py3.6.egg-info}/entry_points.txt +0 -0
- {shelfdb-0.2.1/shelfdb.egg-info → usr/local/lib/python3.6/site-packages/shelfdb-0.2.2-py3.6.egg-info}/top_level.txt +0 -0
usr/local/bin/shelfdb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# EASY-INSTALL-ENTRY-SCRIPT: 'shelfdb==0.2.2','console_scripts','shelfdb'
|
|
3
|
+
__requires__ = 'shelfdb==0.2.2'
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
from pkg_resources import load_entry_point
|
|
7
|
+
|
|
8
|
+
if __name__ == '__main__':
|
|
9
|
+
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
|
|
10
|
+
sys.exit(
|
|
11
|
+
load_entry_point('shelfdb==0.2.2', 'console_scripts', 'shelfdb')()
|
|
12
|
+
)
|
|
Binary file
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import asyncio, shelfdb, dill, re, sys, json, argparse
|
|
2
|
-
from shelfdb.shelf import ChainQuery
|
|
1
|
+
import asyncio, uvloop, shelfdb, dill, re, sys, json, argparse, os
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
class QueryHandler():
|
|
@@ -85,14 +84,17 @@ class QueryHandler():
|
|
|
85
84
|
|
|
86
85
|
if isinstance(self.chain_query, shelfdb.shelf.ShelfQuery):
|
|
87
86
|
entries = []
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
for entry in self.chain_query:
|
|
88
|
+
if isinstance(entry, dict):
|
|
89
|
+
# Keep only dict value from entry.copy() into entries
|
|
90
|
+
entries.append(entry.copy())
|
|
90
91
|
return entries
|
|
91
92
|
elif isinstance(self.chain_query, shelfdb.shelf.Entry):
|
|
92
93
|
return self.chain_query.copy()
|
|
93
94
|
else:
|
|
94
95
|
return self.chain_query
|
|
95
96
|
|
|
97
|
+
|
|
96
98
|
async def handler(reader, writer):
|
|
97
99
|
queries = await reader.read(-1)
|
|
98
100
|
try:
|
|
@@ -111,27 +113,31 @@ async def handler(reader, writer):
|
|
|
111
113
|
await writer.drain()
|
|
112
114
|
writer.close()
|
|
113
115
|
|
|
116
|
+
|
|
114
117
|
def main():
|
|
115
|
-
|
|
118
|
+
arg = argparse.ArgumentParser(description='ShelfDB Asyncio Server')
|
|
119
|
+
arg.add_argument(
|
|
120
|
+
'--host', nargs='?', type=str, default='0.0.0.0', help='server host')
|
|
121
|
+
arg.add_argument(
|
|
122
|
+
'--port', nargs='?', type=int, default=17000, help='server port')
|
|
123
|
+
arg.add_argument(
|
|
124
|
+
'--db', nargs='?', default='db', help='server database')
|
|
125
|
+
arg = arg.parse_args()
|
|
126
|
+
start_server(arg.host, arg.port, arg.db)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def start_server(host='127.0.0.1', port=17000, db_name='db'):
|
|
116
130
|
global db
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
help='server host')
|
|
120
|
-
args.add_argument('--port', nargs='?', type=int, default=17000,
|
|
121
|
-
help='server port')
|
|
122
|
-
args.add_argument('--db', nargs='?', default='db',
|
|
123
|
-
help='server database')
|
|
124
|
-
|
|
125
|
-
args = args.parse_args()
|
|
126
|
-
db = shelfdb.open(args.db)
|
|
127
|
-
|
|
131
|
+
db = shelfdb.open(db_name)
|
|
132
|
+
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
|
128
133
|
loop = asyncio.get_event_loop()
|
|
129
|
-
server = asyncio.start_server(handler,
|
|
134
|
+
server = asyncio.start_server(handler, host, port, loop=loop)
|
|
130
135
|
server = loop.run_until_complete(server)
|
|
131
136
|
|
|
132
137
|
# Serve requests until Ctrl+C is pressed
|
|
133
138
|
print('Serving on {}'.format(server.sockets[0].getsockname()))
|
|
134
|
-
print('Database :
|
|
139
|
+
print('Database :', db_name)
|
|
140
|
+
print('pid :', os.getpid())
|
|
135
141
|
try:
|
|
136
142
|
loop.run_forever()
|
|
137
143
|
except KeyboardInterrupt:
|
|
@@ -143,5 +149,6 @@ def main():
|
|
|
143
149
|
loop.run_until_complete(server.wait_closed())
|
|
144
150
|
loop.close()
|
|
145
151
|
|
|
152
|
+
|
|
146
153
|
if __name__ == '__main__':
|
|
147
154
|
main()
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import shelve, os, uuid
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
from itertools import islice
|
|
6
|
-
from collections import deque
|
|
7
6
|
from functools import reduce
|
|
8
7
|
|
|
9
8
|
|
|
@@ -20,8 +19,10 @@ class DB():
|
|
|
20
19
|
"""Get ``ShelfQuery`` object. create shelf file named ``shelf_name``
|
|
21
20
|
to store entries if needed.
|
|
22
21
|
"""
|
|
23
|
-
if (not
|
|
24
|
-
isinstance(
|
|
22
|
+
if (shelf_name not in self._shelf or
|
|
23
|
+
isinstance(
|
|
24
|
+
self._shelf[shelf_name]._shelf.dict,
|
|
25
|
+
shelve._ClosedDict)):
|
|
25
26
|
shelf = shelve.open(os.path.join(self.path, shelf_name))
|
|
26
27
|
self._shelf[shelf_name] = ShelfQuery(self, shelf)
|
|
27
28
|
return self._shelf[shelf_name]
|
|
@@ -238,7 +239,7 @@ class Entry(dict):
|
|
|
238
239
|
self.update(entry)
|
|
239
240
|
|
|
240
241
|
def _save(self):
|
|
241
|
-
entry = self.copy()
|
|
242
|
+
entry = self.copy() # store only dict data.
|
|
242
243
|
self._shelf[self._id] = entry
|
|
243
244
|
|
|
244
245
|
def delete(self):
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: shelfdb
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Python dict/json DB, Done right for Efficiency and Simplicity
|
|
5
5
|
Home-page: https://github.com/nitipit/shelfdb
|
|
6
6
|
Author: Nitipit Nontasuwan
|
|
7
7
|
Author-email: nitipit@gmail.com
|
|
8
8
|
License: MIT
|
|
9
|
-
Description:
|
|
9
|
+
Description-Content-Type: UNKNOWN
|
|
10
|
+
Description: Python dict/json DB `done right` to make your job done
|
|
10
11
|
Keywords: dict json database
|
|
11
12
|
Platform: UNKNOWN
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.6
|
shelfdb-0.2.1/LICENSE
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Copyright 2017 Nitipit Nontasuwan
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
shelfdb-0.2.1/MANIFEST.in
DELETED
shelfdb-0.2.1/PKG-INFO
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 1.1
|
|
2
|
-
Name: shelfdb
|
|
3
|
-
Version: 0.2.1
|
|
4
|
-
Summary: Python dict/json DB, Done right for Efficiency and Simplicity
|
|
5
|
-
Home-page: https://github.com/nitipit/shelfdb
|
|
6
|
-
Author: Nitipit Nontasuwan
|
|
7
|
-
Author-email: nitipit@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: Python dict/json DB, Done right for Efficiency and Simplicity
|
|
10
|
-
Keywords: dict json database
|
|
11
|
-
Platform: UNKNOWN
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.5
|
shelfdb-0.2.1/README.rst
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
*******
|
|
2
|
-
ShelfDB
|
|
3
|
-
*******
|
|
4
|
-
|
|
5
|
-
.. image:: https://raw.githubusercontent.com/nitipit/shelfdb/master/shelfdb.png
|
|
6
|
-
|
|
7
|
-
Python dict/json DB **Done Right** for **Efficiency** and **Simplicity**.
|
|
8
|
-
|
|
9
|
-
Features
|
|
10
|
-
========
|
|
11
|
-
- Very simple Pyton dict/json Database.
|
|
12
|
-
- Chainable Query.
|
|
13
|
-
- Can remote process on Database Server.
|
|
14
|
-
- Asyncio Server.
|
|
15
|
-
|
|
16
|
-
Install
|
|
17
|
-
=======
|
|
18
|
-
::
|
|
19
|
-
|
|
20
|
-
$ pip install shelfdb
|
|
21
|
-
|
|
22
|
-
Quick Start
|
|
23
|
-
===========
|
|
24
|
-
::
|
|
25
|
-
|
|
26
|
-
import shelfdb
|
|
27
|
-
db = shelfdb.open('db') # Get database
|
|
28
|
-
db.shelf('user') # get table/shelf 'user' from database 'db'
|
|
29
|
-
|
|
30
|
-
# Insert a user
|
|
31
|
-
db.shelf('user').insert({'name': 'Edgar', 'sex': 'm'})
|
|
32
|
-
|
|
33
|
-
# Get the first user whose name is 'admin'
|
|
34
|
-
db.shelf('user').first(lambda user: user['name'] == 'admin')
|
|
35
|
-
|
|
36
|
-
# Get all user whose sex are 'f'
|
|
37
|
-
users = db.shelf('user').filter(lambda user: user['sex'] == 'f')
|
|
38
|
-
|
|
39
|
-
# print() all users whose sex are 'f'
|
|
40
|
-
for user in users:
|
|
41
|
-
print(user)
|
|
42
|
-
|
|
43
|
-
Asyncio Server
|
|
44
|
-
==============
|
|
45
|
-
.. code-block:: bash
|
|
46
|
-
|
|
47
|
-
$ shelfdb
|
|
48
|
-
Serving on ('127.0.0.1', 17000)
|
|
49
|
-
|
|
50
|
-
ShelfQuery Client
|
|
51
|
-
-----------------
|
|
52
|
-
::
|
|
53
|
-
|
|
54
|
-
$ pip install shelfquery
|
|
55
|
-
|
|
56
|
-
::
|
|
57
|
-
|
|
58
|
-
import shelfquery
|
|
59
|
-
|
|
60
|
-
# Connect to DB, default host = '127.0.0.1', port = 17000, db = 'db'
|
|
61
|
-
db = shelfquery.connect()
|
|
62
|
-
|
|
63
|
-
# Make a query
|
|
64
|
-
query = db.shelf('user').first(lambda user: user['name'] == 'admin')
|
|
65
|
-
|
|
66
|
-
# Send query to Database Server and keep result in `user`
|
|
67
|
-
user = query.run()
|
|
68
|
-
|
|
69
|
-
Learn More
|
|
70
|
-
==========
|
|
71
|
-
See documentation at https://pythonhosted.org/shelfdb
|
|
72
|
-
|
|
73
|
-
GitHub
|
|
74
|
-
======
|
|
75
|
-
**ShelfDB :** `https://github.com/nitipit/shelfdb <https://github.com/nitipit/shelfdb>`_
|
|
76
|
-
|
|
77
|
-
**ShelfQuery :** `https://github.com/nitipit/shelfquery <https://github.com/nitipit/shelfquery>`_
|
shelfdb-0.2.1/setup.cfg
DELETED
shelfdb-0.2.1/setup.py
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
setup(
|
|
5
|
-
name='shelfdb',
|
|
6
|
-
version='0.2.1',
|
|
7
|
-
description='Python dict/json DB, Done right for Efficiency and Simplicity',
|
|
8
|
-
long_description='Python dict/json DB, Done right for Efficiency and Simplicity',
|
|
9
|
-
url='https://github.com/nitipit/shelfdb',
|
|
10
|
-
author='Nitipit Nontasuwan',
|
|
11
|
-
author_email='nitipit@gmail.com',
|
|
12
|
-
license='MIT',
|
|
13
|
-
classifiers=[
|
|
14
|
-
'Programming Language :: Python :: 3.5',
|
|
15
|
-
],
|
|
16
|
-
keywords='dict json database',
|
|
17
|
-
packages=find_packages(),
|
|
18
|
-
install_requires=['dill',],
|
|
19
|
-
entry_points={
|
|
20
|
-
'console_scripts': [
|
|
21
|
-
'shelfdb=shelfdb.server:main',
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dill
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|