Anonymous
Could you show complete python code for models?
Anonymous
Eh? You define the model for yourself using the designer. I don't know what "servers" and "maps" are in your application.
Anonymous
Do you mean sample Python code for creating Server and Map instances?
Anonymous
Yes and the attributes (server has attribute "default_map" which is the relation to the map)
Anonymous
map only has id and name :)
Anonymous
Can you see the model using the link I posted a minute ago?
Anonymous
Now i see yes
Anonymous
I thought the relation should be directly to the id of map
Anonymous
now "servers" attribute of map is only virtual or did this exists as attribute in mysql too?
Anonymous
That may be how it is implemented
Anonymous
I thought I can create relation directly between the "default_map" and the id (pk) of map
Anonymous
If you look at the code generated for MySql, Postgres, or Oracle, you can see that that is exactly the constraint that is created
Anonymous
For MySQL: ALTER TABLE `server` ADD CONSTRAINT `fk_server__default_map` FOREIGN KEY (`default_map`) REFERENCES `map` (`id`)
Anonymous
The designer shows you the logical relationship, not necessarily the low-level implementation detail
Anonymous
And there is no 'servers' attribute in the Map table itself. That is a virtual Set that is created by the Pony ORM so that you can access mapA.servers instead of writing SQL "Select server,map where server.default_map=map.id"
Anonymous
If you are used to doing this kind of database coding yourself, you will have to mentally take a step back. Model the relations using the designer, and then let the ORM do the implementation details.
Anonymous
You *could* work this way. Use the design tool to give you the table and default index definitions, then write your own SQL code using the database access libraries - you wouldn't even need to do that in Python. But you would be ignoring some of the ease-of-coding benefits of using an ORM
Anonymous
Since you said that servers have exactly 1 map, then I modeled that as a required attribute. Here is code that would create a map, then create a server that references that map.
Anonymous
with db_session: map1 = Map(name='map_1') server1 = Server(name='Colossus', default_map=map1) # do a query print("server {} uses map {}".format(server1.name, server1.default_map.name))
Anonymous
And this prints out: server Colossus uses map map_1
Anonymous
A little better-looking query and output: print("server {!r} uses map {!r}".format(server1.name, server1.default_map.name)) prints server 'Colossus' uses map 'map_1'
Anonymous
I could have used map1.name for the second argument to format, but that would not have used the relation, it would have just echoed back the attribute of the object I already had.
Anonymous
All fine, I know this from virtual attributes as accessors from other frameworks :)
Anonymous
So what was your question then?
Anonymous
Now've understand I need to use this virtual attributes :)
Anonymous
Thanks
Anonymous
Ah, ok
Anonymous
If you use MySQL, Postgres, or Oracle, I'm pretty sure the db server will keep a log of the actual SQL statements that are executed, so you could see how your virtual attributes translate in the db access statements
Anonymous
Maybe Pony even does that for you in some debug mode - I am still fairly new to using Pony
Anonymous
If Pony doesn't offer that, it would be a nice feature for debugging
Anonymous
Logging incoming queries inside my mySQL server isn't that hard :)
Anonymous
Since I am lazy by nature, I would like Pony to have that capability so that I can use it from my client code, regardless of database backend
Anonymous
I need to turn in, almost 2am for me and work starts early tomorrow - nice talking with you
Lucky
Having this simplified relationship, I have a on-update trigger on Sticker which updates the .modified column on the database. I now realized, that won't be executed if I add/edit tags to a sticker. StickerTag(sticker=Sticker[123], text="some new tag") What would be the best way to change the modified date? Would be a on-update trigger on the StickerTag table, which updates the Sticker.modified, be a good idea? I wan't to avoid doing it manually in application code, as I fear that I forget setting it somewhere. Background is, that the modification timestamp is needed for syncing updated items to the elasticsearch index.
Lucky
Now correct simplified diagram
Alexander
Yes, I think trigger on StickerTag table which updates modified column of the Sticker table is a good idea. You probably need two triggers - one ON INSERT, UPDATE and another ON DELETE
Lucky
Thanks :D
Lucky
Yes, I think trigger on StickerTag table which updates modified column of the Sticker table is a good idea. You probably need two triggers - one ON INSERT, UPDATE and another ON DELETE
For reference, here are my triggers: db.execute( "CREATE OR REPLACE FUNCTION update_tag__sticker_modified_column() " "RETURNS TRIGGER AS $$ " "BEGIN " " IF (TG_OP = 'UPDATE') OR (TG_OP = 'INSERT') THEN " " IF NEW.sticker IS NOT NULL THEN " " UPDATE sticker SET modified = now() WHERE file_id=NEW.sticker; " " END IF; " " RETURN NEW; " " ELSIF (TG_OP = 'DELETE') THEN " " IF OLD.sticker IS NOT NULL THEN " " UPDATE sticker SET modified = now() WHERE file_id=OLD.sticker; " " END IF; " " RETURN OLD; " " END IF; " " RETURN NULL; " # result is ignored since this is an AFTER trigger "END; " "$$ LANGUAGE 'plpgsql';".replace("$$", "$$$$"), dict()) db.execute( "DROP TRIGGER IF EXISTS update_sticker__tag_insert ON tag;", dict()) db.execute( "DROP TRIGGER IF EXISTS update_sticker__tag_update ON tag;", dict()) db.execute( "DROP TRIGGER IF EXISTS update_sticker__tag_delete ON tag;", dict()) db.execute( "CREATE TRIGGER update_sticker__tag_insert AFTER INSERT ON tag " "FOR EACH ROW EXECUTE PROCEDURE update_tag__sticker_modified_column();", dict()) db.execute( "CREATE TRIGGER update_sticker__tag_update AFTER UPDATE ON tag " "FOR EACH ROW EXECUTE PROCEDURE update_tag__sticker_modified_column();", dict()) db.execute( "CREATE TRIGGER update_sticker__tag_delete AFTER DELETE ON tag " "FOR EACH ROW EXECUTE PROCEDURE update_tag__sticker_modified_column();", dict()) orm.commit()
Lucky
Any Idea what I rights do I have to set to solve Error: must be owner of function update_tag__sticker_modified_column (First db.execute)
Alexander
I think the function was created under another database user previously (maybe root), and current user has no right to replace it
Lucky
Deleting it the 3rd time helped, indeed.
Lucky
Thanks
Anonymous
@luckydonald - I think your tip re orm.sql_debug is just what I was looking for, I'll give it a try next time I'm in Ponyworld
Lucky
Great to help back.
Lucky
What could be a reason for pony.orm.dbapiprovider.OperationalError: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. ? I have postgres (9.5.0) running on localhost. db.bind("postgres", user='postgres', password='', host='localhost', database='postgres') The first table got created.
Alexander
From my understanding there may be many reasons http://stackoverflow.com/questions/15934364/psql-server-closed-the-connection-unexepectedly
Lucky
It was a error with pg_hba.conf and somehow the port being occupied by something else.
Lucky
I think pony.orm.dbapiprovider.ProgrammingError: column "user" does not exist should also tell you the table.
Lucky
Would adding content be possible anyway? I even searched the logs.
Lucky
I could think of two ways: Add metadata to the exception (e.g. table="Fooo") Adding logging (e.g. logger.debug("Creating mapping for table {table!r}".format(table="Foo"))
Lucky
This would probably be in DBObject
Lucky
Is there somewhere a place to discuss how migrations will work?
Alexander
Right here, or you can message me directly
Lucky
I think here is better for everyone.
Anonymous
Is it okay for me to sell my apps using Pony ORM as the database?
Anonymous
Can I develop modules to improve Pony ORM as well? I see this ORM is raisingly
Alexey
Anonymous
I still don't have an idea of it
Anonymous
Is there any big company use Pony ORM already?
Anonymous
I look into Pony ORM syntax is Pythonic
Alexey
I look into Pony ORM syntax is Pythonic
This was the main goal to have it Pythonic Other two - easiness of use and performance
Alexey
Is there any big company use Pony ORM already?
Big companies that bought licenses, before we released under Apache 2.0, were Cisco and PremiumBeat. Also Ideco uses it. Think now more companies use it, after we released Pony under Apache. Also we can see that a number of companies and tech universities use the Editor. One of them is SAP.
Anonymous
wow, nice to hear that..Changing the licensed is a good decision.
Anonymous
Now I don't have to worry about license legality to deploy my apps. I intend to help Pony ORM developments once my apps is going to be used widely by my clients.
Alexey
Can you share what kind of app is that?
Alexey
Or the site name?
Anonymous
We try to make systems in the hospitals based on web but with no Frameworks (less).
Anonymous
We still develop it ,almost reach about 40% until it will works .we Haven't decide the database which are going to be used .
Anonymous
I believe ORM method would be just fine and Pony ORM is one of my preferred suggestions
Alexey
Do you consider using AWS?
Anonymous
Whats a AWS?
Alexey
Amazon Web Services
Anonymous
Amazon Web Services
Ouuu..I don't know.why you asked?
Anonymous
This is one of my projects https://www.korbanaqiqah.com
Anonymous
It use Django Framework and MySQl as the database..But I plan to convert it to just use other ORM than Django ORM
Anonymous
I know it s hard to get other ORM will works in Django..so Now ,we are trying to not using Django anymore for our next projects