Comments (7)
I probably ran the example using Python 2.x.
from unqlite-python.
Yes, I'm on 3.x, I'm not sure if this is an issue or not now, closing just in case.
from unqlite-python.
This issue is easily reproducible using the following code:
Python 3.6.5 (default, May 11 2018, 04:00:52)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import unqlite
...:
...: db = unqlite.UnQLite()
...: collection = db.collection('users')
...: collection.create()
...:
...: user_id = collection.store({'name': 'Johnson'})
...: collection.fetch(user_id)
...:
...:
{'name': b'Johnson', '__id': 0}
I'm not sure I understand, is this regarded as acceptable 3.x behavior? If so then this does not look right to me. Can we reopen this issue?
from unqlite-python.
It's not a bug, this is expected behavior -- data is stored as bytestrings.
from unqlite-python.
Internal storage representation aside, the way the provided interface works is the one that strikes me as odd. Some values when marshaled/unmarshaled keep their correct type but a string type is treated differently. Take a look at the following example:
import unqlite
db = unqlite.UnQLite()
collection = db.collection('users')
collection.create()
name, age, height = 'Johnson', 34, 2.4
friends = ['Alex', 'Maria']
phone_numbers = [123112, 2255223, 223131345]
user_id = collection.store({
'name': name,
'age': age,
'height': height,
'friends': friends,
'phone_numbers': phone_numbers
})
user = collection.fetch(user_id)
print(user)
print(type(name), type(age), type(height), type(friends), type(phone_numbers))
print(type(user['name']), type(user['age']), type(user['height']),
type(user['friends']), type(user['phone_numbers']))
.. which yields the following output:
{'name': b'Johnson', 'age': 34, 'height': 2.4, 'friends': [b'Alex', b'Maria'], 'phone_numbers': [123112, 2255223, 223131345], '__id': 0}
<class 'str'> <class 'int'> <class 'float'> <class 'list'> <class 'list'>
<class 'bytes'> <class 'int'> <class 'float'> <class 'list'> <class 'list'>
int
, float
and list
are unmarshalled as their respective types, wouldn't you normally expect a string to be unmarshalled as its respective type as well?
from unqlite-python.
wouldn't you normally expect a string to be unmarshalled as its respective type as well?
How do you know the difference between a utf8-encoded text string and a raw binary bytestring? Keys are considered text, hence they are decoded, but values are treated as opaque bytes.
from unqlite-python.
Keys are considered text, hence they are decoded, but values are treated as opaque bytes.
I see. I'm not too familiar with UnQLite itself so I should have read the docs beforehand. Thanks for clearing that up, it makes sense now.
from unqlite-python.
Related Issues (20)
- collection fetch, anyway it will return a value HOT 1
- Update db entry in multiple threads HOT 6
- Question about multithread HOT 2
- Use in multi-process environment? HOT 2
- Flags unavailable via Python HOT 2
- Retrieved values are byte strings (Python 3.7) HOT 6
- Wrong kwarg name in UnQLite() API docs.
- AsyncIO Support? HOT 5
- ValueError when inserting to nonexistent collection HOT 2
- collection.store returs int HOT 3
- empty_collection.last_record_id() is 0 HOT 1
- FR: Binary releases on PyPI HOT 3
- Collection cursor only returns first record HOT 16
- Collection reverse iterator HOT 1
- Unqlite on python 3.10 fails with unqlite.cpython-310-x86_64-linux-gnu.so: undefined symbol: _PyGen_Send HOT 8
- Readme update HOT 1
- Import error HOT 3
- Is it possible to use a samba shared database file? HOT 1
- Cannot install unqlite 0.9.4 on Windows HOT 3
- Latest pip install asks for moving away from setup.py HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unqlite-python.