Lucky
You mean editor.ponyorm.com? This was often requested so far, but I think it is still not possible.
csa3d
csa3d
Jonah
hey folks has anyone considered a simple API into to pull models and sql into code from diagram editor ? Is there scraping code for this?
Alexey
Sounds interesting @minskmaz!
Could you describe how would you use it?
Jonah
yah after I update the model a hook would be triggered passing both the model and the db code (based on the post) - that would write the changes to git / a diff and migration would be generated
Jonah
right now it's just copy paste endless.
csa3d
Can properties handle condition logic like:
return True if self.is_true and self.other is not None else False
Alexander
you mean, inside query?
csa3d
Yes, as a select filter
Alexander
yes, you can, it should be translated to SQL
csa3d
select(x for x in Ent if x.property)
Alexander
yes
Alexander
it was not easy to implement :)
csa3d
Hmm, OK i will dig further
csa3d
Having bad luck here
Alexander
you mean, it doesn't work?
Alexander
property code should consist of a single return statement
Alexander
like in a lambda function
csa3d
I comprehended it into a single line.. Specifically:
return True if not self optionally.is_empty() or self.other is not None and self.other > 0 else False
csa3d
One is a set the other is optional count
csa3d
Property works outside of main select but not inside
Alexander
what is self optionally.is_empty() ?
csa3d
pony.orm.Set("AnEntity")
csa3d
Holds groups of related entities
Alexander
so you probably missed a dot while copy-pasting the code
Alexander
I mean, between self and optionally
csa3d
True, sorry mobile
Alexander
ok
csa3d
It's valid code in Pycharm
Alexander
ah, you use if-expressions. It is not supported by decompiler yet (if-expressions has unusual bytecode)
you can rewrite it to avoid if-expression, like:
return self.optionally.is_empty() or self.other is not None and self.other > 0
csa3d
Corp won't allow
csa3d
;) thus vagueness
csa3d
Attribute error: 'NoneType' object has no attribute 'src'
csa3d
asttranslation.py
Alexander
Can you provide full traceback?
Alexander
by the way, you can write just "self.optionally" instead of "self.optionally.is_empty()"
csa3d
csa3d
Alexander
In general properties should work, but maybe you used something unusual. I'll try to reproduce and fix it
csa3d
Thanks. Love me some Pony
csa3d
It's fantastic to have dev be this accessible as well, so thank you
csa3d
Alexander
hmm
Alexander
because "x.is_empty()" should be equal to "not x"
Alexander
so you need to add "not"
csa3d
OK, if not self.set.is_empty() == if self.set
csa3d
Much more readable
csa3d
OK, I figured out my issue
csa3d
Property failed when writing like:
return True is this or that else False
but works when written
return this or that
csa3d
That wasn't obvious from the trace back, which had me second guessing my data structure
Alexander
As I said, if-expressions (a if b else c) doesn't work yet
csa3d
Sorry if I missed that point
csa3d
Now I see it, derp
csa3d
Ty
Alexander
From the traceback I see that Pony tried to throw exception "Expression <...> was too complex to decompile", but during exception text generation unexpectedly catch another error. I'll try to fix that
Alexey
Matthew
https://github.com/gperinazzo/dict-derive This looks like it could make using pony with rust pretty easy
Permalink Bot
Matthew
MyEntity.to_dict() and then rust can use pony data natively
Anonymous
Does the Json type not work? It sometimes tries to do a CAST(%s AS JSON), which just results in an SQL syntax error...
Alexander
What database do you use?
Anonymous
mariadb
Anonymous
10.4.12, if it matters
Alexander
It seems that MariaDB has some differences with JSON handling comparing to MySQL
Anonymous
Guess for the time being, I'll have to change the type to LongStr and do the conversion myself. Will break automatic table creation, but I don't actually need that, so it should be fine
Anonymous
Is the cast necessary with Oracle mysql? MariaDB seems to just consider the json field as a longtext with extra constraints
Anonymous
Well, you also lose all the other json specific features. Which I don't need at current, but that is a bit of a bummer, gotta say
Alexander
I'll try to look into it tomorrow. Sorry, have no time right now...
Currently Pony does not officially support MariaDB, maybe it is not too hard to fix JSON support for MariaDB
Anonymous
Hmm... MariaDB is pretty much the only DB I use. The differences between Oracle and Maria are usually pretty minimal, though, so maybe it won't be a huge problem.
Still, this could cause problems down the line...
As for "no time right now": I would never expect you to do something about it right away. I'm happy if it gets fixed in a month, to be honest. :D
Alexander
Ok, I think in a month a can found a time to fix it :)
Currently we a trying to finish migrations
Jonah
@metaprogrammer excited about migrations - I've been using migra in python. It's fairly manual but works. Have you tried it?
Jonah
can you recommend tools or best practices for migrating the actual data -- preferably python!
Whitespine
Hey all, (hopefully) quick question. I'm using python3, pony very 0.7.11, to generate a new MySql database. I'm running into some issues with string encoding (I think?)
Whitespine
'Incorrect string value: '\\xE2\\x80\\xA8and...' for column 'ActionText' at row 1"...
Alexander
Can you share you code example?
It actually looks like an encoding error.
csa3d
Silly question, what's the best way to slice last two select results
csa3d
select() [:] [-2:]
David
select() [:] [-2:]
Remove first brackets to not getting all data from database
Select()[-2:]