Kyle
How can I disable auto db_session on debug mode?
Kyle
Sometimes I forget to do actions inside a session but it gives me no error since I run in debug mode in my machine but when deployed the app won't work fine and sometimes it's hard to find what's causing since it's mostly async functions
Jim
Pony doesnt support async
Igel
I have a database, with tables Roles, Posts, Users ... Nothing too crazy. But i cant seem to get past 'table blah.users doesnt exist' ... so what i do, is i just create a table called Lusers, and copy the same code used for Users.. and it works. where should I look?
Igel
oh shh.... its case sensitive.. what..?
Igel
the code is running on osx, uhhhhh am i screwed? all my tables have an upper case first letter
Matthew
You can manually set the table name for a pony model
Igel
im looking for this in the api docs ... ok
Igel
do you know it off hand? Im burning mental cycles over this heh
Matthew
it's something like table = 'xyz'
Matthew
that's with underscores
Matthew
__table__ == 'xyz'
Igel
OK
Alexander
Single underscores: _table_ = 'xyz'
Igel
got it!
Igel
🤘
Igel
invalid literal for int() with base 1: '1hioft8iz8dht....'
Igel
i use unique strings for Id's / primary keys.. hmm
Matthew
you need to change to having an explicit field in your model which is a primary key
Igel
i set it Id = required(str, 26, unique=True)
Igel
(capital Requir.)
Matthew
change Required to PrimaryKey
Igel
daaamn :)
Igel
viola!
Igel
❤️
Igel
thanks again i should be good!
Igel
i got 2 databases i am going to do some merge between the two so.. How can I duplicate class Users(db_left.Entity) and class Users(db_right.Entity) .. Initially i was just doing class Users(Database().Entity) but thats not accurate i guess.. both db schemas are the same
Igel
may be i can just make it users_left and users_right, and change _table_ attr ... no worries.. really psyched ive got that resolved, cheers
RdfBbx
Hello there! I am trying to create a database for cryptocurrency monitoring in the following structure. Table users (each user can monitor different addresses) class User(db.Entity): telegram_id = Required(int, size=64, unique=True) username = Optional(str, unique=True) addresses = Set('Address') addressbook = Set('AddressName') A table of addresses (each address can be viewed by different users) class Address(db.Entity): operator = Required(str, unique=True) users = Set('User', reverse='addresses') events = Set('Events', reverse='e_addresses') addressbook = Set('AddressName') The name table addresses (each user can have own custom name for each address) class AddressName(db.Entity): user = Required(User) address = Required(Address) name = Optional(str) And I need a table in which each user can assign for each address one or more events in the blockchain for this wallet. My example here (I think its wrong) class Events(db.Entity): event_id = Required(int, size=64, unique=True) event_name = Optional(str, unique=True) e_addresses = Set('Address') For example, the user User1 follows the wallets Wallet1, Wallet 2 and set the wallet Wallet1 subscription to events Event1, Event2, Event3. And for the Wallet 2 wallet, it didn't subscribe to events. Please tell me how to build such a table. I was thinking about making the events in the table a List (if possible).
Matthew
When you say Wallet do you mean the Address model?
Matthew
So an event can be subscribed to by multiple addresses, and each address can have multiple events?
Matthew
If so, you would need a many to many relationship I think https://docs.ponyorm.org/relationships.html#many-to-many-relationship
Matthew
Oh but probably AddressName <-> Event, not Address <-> Event, so that each user can manage subscriptions independently
Santosh
Class Device (db.Entity): Id=PrimaryKey(str) user=Set("User") Class User(db.Entity): Id=Primary Key (str) device = Optional (Device) In this I want get all devices belonging to particular user How do I query
Santosh
I know relation should have been reversed for one to many but please help
Santosh
@metaprogrammer your support would be really helpful
Matthew
Device.select(lambda d: d.user == some_user)
Santosh
u = User["test"] de = Device.select(lambda d:d.user==u)
Santosh
I get incompatible type error
Matthew
screenshot it
Santosh
Matthew
change it to "u in d.user"
Santosh
Matthew
in device i suggest you rename the user field to users as it is multiple users
Santosh
Santosh
No luck still
Santosh
Incomparable Exception
Santosh
Btw I am ob MySQL
Matthew
you used == when I said "in"
Santosh
this
sorry miss understood This
Alexander
> I want get all devices belonging to particular user In your models you have multiple users for a single device, and a single device for each user. So you can do just user.device to get this single device if you already have a user. You cannot have more than one device for a single user, because your schema does not allow it. Or you need to change it to: class User(database.Entity): ... devices = orm.Set(lambda: Device) if user should be able to work with multiple devices. And then, if you have an instance of user, you can do user.devices to access all its devices
Anonymous
wow Notepad++
Volbil
wow Notepad++
Something wrong about it?
Evgeniy
Hi! Is an analog of signals from Django in Pony?
Alexander
Hi! Is an analog of signals from Django in Pony?
You can use hooks: https://docs.ponyorm.org/api_reference.html#entity-hooks
Alexander
Not a direct analog of signals, but can be used for similar use-cases
Evgeniy
Thank!
Evgeniy
More question. Is there an analog of the method get_or_create() from Django in Pony?
Alexander
No, but you can do MyEntity.get(**kwargs) or MyEntity(**kwargs)
Evgeniy
Good idea, thank
Igel
this community rocks for support. 👍
Lucky
for table_name, table_clazz in db.entities.items(): AttributeError: 'NoneType' object has no attribute 'entities'
Lucky
Did `.entites` break in some recent pony release?
Lucky
Ah wait. db seems to be None then.
Lucky
Interesting. Might be my side though.
Santosh
How do we connect to DB with ssh tunneling
Santosh
We can connect with pymysql
Santosh
But how do do with ORM
Alexander
I think you can establish ssh tunnel outside of process with pony, and then connect to a localhost port
Alexander
You probably don't need any specific support from pony for this
João Rosal
Hi Everyone. First off, hat tips to the pony developers. I’ve been using it for a few months and it has been great!
João Rosal
Second, has onyone tried working with MariaDB using pony? Many thanks in advance
Alexander
Hi! Pony officially does not support MariaDB at this moment, but mostly it should work. MariaDB has different syntax for JSON expressions in queries, so JSON expressions may not work
Vitaliy
Hello, Alexander! I want to ask your opinion as co-founder of Pony: what is the best approach to implement multi-language in DB architecture using Pony? Suppose I'm designing a diagram of some CMS, and I have a Document entity with following attributes: title, description, content (omit all unnecessary). All of them should be represented in all languages defined in the system (via Language entity). I see several approaches: 1) To use Json type for such columns, i.e. Document[1].title = {'ru': 'Тестовый документ', 'en': 'Test document'} Pros: - easy to retrieve data w/o joining additional tables Cons: - might not be suitable for content which can store too large data 2.1) To use additional entity like String which related to Language (1:M relation type) and to all of the fields of Document via M:1, i.e.: Document(title=[String(lang='en', value='Test document'), String(lang='ru', value='Тестовый документ')]) Pros: - seems it is most flexible way Cons: - the String entity should contain back-refs to each field of Document (title, description, content). But what if we need to localize another entities, like Template, Chunk, Property etc? I think String definition will be too messy. - more complex select with join, like select((d, t) for d in Document for t in Translation if t.language.code == 'en') - not quite convenient way to access localized strings as in (1) 2.2) To use intermediary entity Translation which encapsulates all of the fields to be localized. Maybe also to use inheritance for particular entities, like DocumentTranslation, PropertyTranslation etc which will add specific attributes if it needed. Pros: - organize messy code of abstract String entity Cons: - the same as in (2.1) 3) To use hardcoded attributes like title_ru, title_en, content_ru, content_en. Pros: - easy access to attributes w/o joining Cons: - not so easy to add new language Maybe I'm missing something? What can you advice? Thank you!
João Rosal
Worth pointing out that MaraiDB now has a dedicated package to connect python to its server: mariadb.