Code Monkey home page Code Monkey logo

Comments (7)

coleifer avatar coleifer commented on June 12, 2024

I probably ran the example using Python 2.x.

from unqlite-python.

 avatar commented on June 12, 2024

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.

zoopp avatar zoopp commented on June 12, 2024

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.

coleifer avatar coleifer commented on June 12, 2024

It's not a bug, this is expected behavior -- data is stored as bytestrings.

from unqlite-python.

zoopp avatar zoopp commented on June 12, 2024

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.

coleifer avatar coleifer commented on June 12, 2024

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.

zoopp avatar zoopp commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.