Alexey
Welcome to Pony ORM group! Here you can discuss anything related to Pony ORM.
Mikki
Woohoo! Hello!
Mikki
Welcome :)
Anonymous
Здрасте
Anonymous
Hello
Mikki
Heya! ^^
Jannes
Rozen
:O
Rozen
Hi :D
Mikki
Hello, welcome!
Rozen
thanks :D
Rozen
god it took me too long to find this grup
Mikki
Its just here -since a week or such
Rozen
oh
Mikki
So where did you run into?
Rozen
ah yes
Rozen
well i usually have stupid questions 😆
Rozen
now, what i'm looking for is to know if it has any sense to have a property in my class that is a Set(str)
Mikki
No question is stupid 😁
Mikki
What's the problem you're running in to, to use that as a solution? :)
Rozen
i just need that my "class" to have a list of strings
Alexander
Hi everybody! @Rozzen, what database do you use?
Rozen
sqlite3
Alexander
Right now Set attributes can be used only with entity types, but in the distant future we can add support of Set(str) as well. At this moment you can store array of strings inside Json attribute: class MyEntity(dn.Entity): name = Required(str) tags = Optional(Json) ... x = MyEntity(name='foo') x.tags = ['one', 'two', 'three']
Rozen
:O
Rozen
that should be fine i guess
Rozen
thanks :D
Alexander
We support Json attribute in all databases (SQLite, MySQL, PostgreSQL, Oracle). To get best performance with SQLite you should compile it with json1 extension, but Json will work without that extension too, just a bit slower.
Rozen
mmm what do you mean with "compile with json1 extension"? 😆
Alexander
As I understand it, SQLite does not include Json1 extension by default, and you need somehow enable it: https://www.sqlite.org/json1.html https://www.sqlite.org/loadext.html
Rozen
ooh
Alexander
It is not necessary, you can use PonyORM Json type without json1 extension.
Rozen
i get it, but i love to learn those things
Alexey
https://docs.ponyorm.com/json.html
Rozen
it's mandatory to use C?
Alexander
As I understand, yes. Actually, I have no experience with compiling that stuff myself. Maybe someone can explain better. There is an blog post of Charles Leifer in which he describes how to build SQLite with json1: http://charlesleifer.com/blog/using-the-sqlite-json1-and-fts5-extensions-with-python/
Alexey
if you don't care about performance at this point, you don't need the JSON1 extension
Rozen
if you don't care about performance at this point, you don't need the JSON1 extension
yes yes i got it, but i'd like to understand how to get more optimization in the future
Alexander
I think it would be more convenient if future versions of SQLite include json1 by default
Alexey
check out this article http://charlesleifer.com/blog/using-the-sqlite-json1-and-fts5-extensions-with-python/
Alexey
so currently you can just use SQLite as is and once you'll see that you need better perfomance with JSON, you can think about compiling it with JSON1 module
Rozen
but at least i know what to read when that happens
Rozen
stupid question number two!
Rozen
to set an image as a property?
Alexey
usually it is a str - because you probably will keep an image url in this property
Alexander
You can also store an image as a BLOB data inside the database (use buffer type for that), but usually it is much better to save images outside of the database and store the filename in a textual column.
Rozen
silly question number 35! (?)
Rozen
let's say i have a class Human(db.Entity): that has the propery pet = Required(Animal)
Rozen
and i have the class Dog(Animal)
Rozen
and i have a variable is a dog
Rozen
so... i want to do something like a select(h for h in Human if h.pet == dog)
Rozen
but dog isn't an animal, it's a dog, a child class of animal
Rozen
and python implotes when i try to do that
Rozen
sorry my english isn't tha best
Alexander
I think it should work. Maybe the error is caused by some other reason. Can you provide a traceback with the error message?
Rozen
grr i just fixed using ids
Rozen
when i have time again i'll try and if it fails
Rozen
i'll send the error message
Rozen
now i got the error
Rozen
<class 'pony.orm.sqltranslation.IncomparableTypesError'> ("Incomparable types 'Animal' and 'Set of Dog' in expression: h.pet == dog",)
Rozen
aah
Rozen
because i have like
Rozen
class Dog(Animal): humans = Set("Human")
Rozen
h in dog.humans
Rozen
h in dog.humans
should be this way?
Rozen
ok i changed to that and now i get
Rozen
<class 'TypeError'> ("Expression dog.humans has unsupported type 'Set'",)
Alexander
Can you show how you got the value of the dog variable
Alexander
It seems that it is not a dog, but a set of dogs
Rozen
i have a one to one relationship with some id that isn't the primary key
Rozen
dog= Dog.get(oexr_id = id)
Alexander
Can you paste the definitions of Animal, Dog and Human classes?
Rozen
yep gimme a sec
Rozen
pastebin or right here?
Alexander
any way
Rozen
class Animal(db.Entity): id_animal =PrimaryKey(int,size=64,auto=True) humans =Set("Human") classtype = Discriminator(str) _discriminator_="Animal" oexr =Required(OnlyExr) class Human(db.Entity): user =Required(User) pet =Required(Animal) classtype = Discriminator(str) _discriminator_="Human" class OnlyExr(db.Entity): id_exr =PrimaryKey(int,size=64) animals =Set("Animal") name =Required(str) class Dog(Animal): race =Optional(String) _discriminator_="Dog"
Alexander
It looks strange that in your schema a human can has only one (required!) pet, while a pet belongs to many humans. I think it should be the other way
Alexander
class Animal(db.Entity): ... owner = Required(Human) class Human(db.Entity): ... pets = Set(Animal)