AnswerDotAI / fastlite

A bit of extra usability for sqlite
https://answerdotai.github.io/fastlite/
Apache License 2.0
144 stars 12 forks source link

`transform` keyword doesn't work outside core.ipynb #21

Open pydanny opened 3 weeks ago

pydanny commented 3 weeks ago

This script doesn't appear to work:

from fastlite import *

db = Database(':memory:')

print('original')
class User: name: str; age: int
print(User.__annotations__)
users = db.create(User, pk='name')
print(users.__repr__())

print('-'*20)
# Transform!
print('transformation to add pwd:str field')
class User: name: str; age: int; pwd: str
print(User.__annotations__)
users2 = db.create(User, pk='name', transform=True)
print(users2.__repr__())

This should return this string:

original
{'name': <class 'str'>, 'age': <class 'int'>}
<Table user (name, age)>
--------------------
transform
{'name': <class 'str'>, 'age': <class 'int'>, 'pwd': <class 'str'>}
<Table user (name, age, pwd)>

Instead, it returns this:

original
{'name': <class 'str'>, 'age': <class 'int'>}
<Table user (name, age)>
--------------------
transform
{'name': <class 'str'>, 'age': <class 'int'>, 'pwd': <class 'str'>}
<Table user (name, age)> # <----------------------------------------- missing pwd

Additionally, this doesn't work in index.ipynb of this repo. Add this to the bottom cell:

class Cat: id:int; name:str; weight:float; uid:int; breed:str
cats = db.create(Cat, transform=True)
cats

The result that should be returned is missing fields, specifically uid and breed:

<Table cat (id, name, weight)>