Micaiah
What would be the best way to write code that takes an entity and produces an WTForm
Alexander
Currently we don't have a ready solution, but if you want some generic code, you can analyze obj._attrs_ or entity_class._attrs_ in order to see attribute definitions
Micaiah
My current plan was the use _attrs_, thanks
Micaiah
Where can I find all of the possible data types for columns, so I can map them to form types?
Alexander
Each data type has corresponding database converter class in dbapiprovider.py (the converter classes are inherited and redefined in specific providers such as dbproviders/sqlite.py)
Micaiah
Alexander
Micaiah
Is there anything like sandman2 for PonyORM?
Alexander
I'm no aware of that
Alexander
I think no
Micaiah
https://github.com/jeffknupp/sandman2
Micaiah
its a start
Micaiah
but this is pretty gross code
Romet
90% of the time you don't want a directly generated REST API
Romet
that being said, something like DRF for pony would be neat
Micaiah
90% of the time you don't want a directly generated REST API
I agree, this is mostly just an experiment
Micaiah
How can you access the length attribute of a string entity?
Lucky
len("bla")
Micaiah
len("bla")
I worded that poorly, I meant the max length. For example, if you had a field last_name = Required(str, 15)
Anonymous
I neeg to learn english more , it's hard to understand about the discussion was telling
Anonymous
need*-
Anonymous
the sun begin raise here and going sunset there...he2, sorry, out of the topic
Anonymous
anyway, in the case of making GUI Desktop applications. so, I have to call the pony instances object and put it in my GUI event ?
Anonymous
example @db_session def myproductName(iproduct): prdt = product[iproduct] print prdt.name def eventhandlercase(self,event): iproduct = self.getvalue(onbuttonclick) myproductName(iproduct) is that correct?
Alexey
I worded that poorly, I meant the max length. For example, if you had a field last_name = Required(str, 15)
>>> from pony import orm >>> db = orm.Database('sqlite', ':memory:') >>> class E1(db.Entity): ... name = orm.Required(str, 40) ... >>> db.generate_mapping(create_tables=True) >>> db.E1.name.converters[0].max_len 40
Micaiah
What is stored in converters?
Alexey
functions that convert value from py to sql and back
Micaiah
Gotcha, thanks
Micaiah
Is length consistant between converters?
Alexey
it is equal to the number of columns which are required to store an attribute
Alexey
for the most cases it is 1 but in Pony you can have attributes that require more than one column in the database to store it
Micaiah
Like composites?
Alexey
yes
Micaiah
Still trying to work out the best way to convert an Entity to a FlaskForm subclass, I was just going to go through each of the fields and iterate through a conversion function, but there are so many things to keep track of that the function becomes pretty crazy after just a few field types. I think I might be better off subclassing PrimaryKey, Required, Optional, and Set
Cristian
i am working with pony to read data from existing sqlite db, i got this error (comment has models) https://gist.github.com/ovnicraft/ccf6800a551d3cf67ffc7b5460be71fc
Cristian
so my Q is: Entity always need id attribute _
Cristian
?
Alexander
@b00t5tr4p no, it is not necessary for entity to have id attribute, but it should have a primary key. If no primary key defined, default primary key attribute with id name added automatically. You can explicitly specify another attribute as a primary key
Alexander
example @db_session def myproductName(iproduct): prdt = product[iproduct] print prdt.name def eventhandlercase(self,event): iproduct = self.getvalue(onbuttonclick) myproductName(iproduct) is that correct?
It depends on the architecture of your application. You need to keep in mind that db_session scope should be short, and objects should be used within that scope. Typical use case for PonyORM is a web application, where objects are retrieved from the database during the processing of HTTP requests, and discarded when the HTML page is generated. If you want to develop a GUI application, the question is how many users can connect to the same database at the same time. If it is more than one user, you should have short db_sessions, and between them keep object ids instead of objects
Anonymous
okay. , I l try your suggest. Do you have any documentation that is refer to db_session for many users access in the same database?
Alexander
db_session documentation is here: https://docs.ponyorm.com/transactions.html db_session specifies transdaction boundaries. If multiple users are working with the same database, each should work in a separate transaction
Anonymous
okay,, thanks. I ll read it right away..
Anonymous
so db_session will accumulate objects before they are being committed, am I right?
Anonymous
and I could just use commit() between transactions in the same db_session, (if i don't want to separate the transactions)
Alexander
yes. If you use manual commit(), you can continue working with the same objects, but they may become out-of-date if another user did some changes
Alexander
And then Pony will check upon save that the object in the memory have the same data as the object in the database
Anonymous
ah...I see
Micaiah
Can you programmatically get the mypy types from the parameters of a function?
Anonymous
I wonder if there is some tools to convert from sql script into pony orm instantly..
Anonymous
so I don't have to write new schema in the online editor once I had already got the sql version
Alexander
Right now there are no such a tool, maybe we will add it in the future
Anonymous
Okay , . I hope
Anonymous
so
Anonymous
Hi all, I'm having a hard time trying to get a sql like with multiple percentage signs: %str1%str2%str3%. I have this: users = select( u for u in User if user_input.join("%") in u.name ) but it doesn't work the way I expect.
Alexander
Hi Manuel, what database do you use?
Anonymous
sqlite
Alexander
You can embed raw_sql fragment into your query: like_str = '%str1%str2%str3%' users = select(u for u in User if raw_sql('u.name like $like_str'))
Anonymous
thanks! that will do
Anonymous
Does the % character suffers any special escaping?
Alexander
In the variant I suggested, no
Anonymous
my first query was wrong, this is the right one: users = select( u for u in User if "%".join(user_input.split()) in u.name )
Anonymous
so a alex ko string would be %alex%ko%
Alexander
my first query was wrong, this is the right one: users = select( u for u in User if "%".join(user_input.split()) in u.name )
In that variant pony will escape % signs in order to keep Python semantics of in operation
Anonymous
Thanks, the raw_query variant seems perfect. Nice work with Pony!
Lucky
I suspect get_current_user() to return nothing.
Lucky
>>> repr(orm.get_current_user()) 'None'
Alexander
_get_schema_dict returns only a subset of entities whch current_user has rights to see
Lucky
>>> repr(orm.core.local.current_user) 'None'
Lucky
But I don't understand why that user is None. I can query the database.
Alexander
You need to call set_current_user before
Lucky
with what input? The database user I gave at db.bind?
Lucky
like orm.set_current_user('postgres_user')?
Alexander
No, typically a user is an entity instance from the database. If you want to show all entities to any unregistered user, just set permissions accordingly with db.permissions_for(Entity1, Entity2, ...): allow('view', group='anybody')
Lucky
Oh, this is the has_perm stuff from ponyJS
Alexander
yes
Lucky
Ah, I thought that would only be checked in .to_json()