Are Model Classes available in Uplink code?

What I’m trying to do:
Get some information that I can use for making design decisions.

Currently, I use “raw” data table rows in one of my Uplink programs, for communication back to the main App and its users. This will continue to work, of course.

But Best Practices says “Describe all operations in your model class”, and in this case, some of those operations occur in my Uplink programs.

1 Like

I have the same question. I’m trying to figure out how to import model classes into my server uplink code so that I can access functions and properties of those classes there.

I haven’t tested this myself, so it’s just an assumption based on how things usually work, but I’d expect it to function correctly.

You just need to clone the app to your computer, then configure your uplink script to import modules from that cloned app. Just make that your anvil-uplink package is up to date with the latest version.

Given when Anvil Uplink was last updated, vs. when the feature was added Server-side, I’d expect otherwise.

Edit:
Anvil Uplink v0.5.2 published 2024-10-30
Model Classes announced 2025-02-17

So I do not expect to be able to define Model Classes in my Uplink programs until a future version of Anvil Uplink.

1 Like

Good question — I’ve wondered the same thing when splitting logic between the app and uplink scripts

Welcome to the Forum!

Yes. I suspect that there is a core of database integrity logic that should be common to all of a Table’s Model Classes. Uplink, Server, and Client can each add their own specific queries and procedural logic, on top of that.

This could be a natural use of Python’s multiple inheritance for classes, though I’m not sure what that would look like in this case.

We have now released anvil-uplink version 0.6.0, supporting Model Classes (and a few other goodies, including nicer logging).

You can now use your Model Classes from the Uplink, as you correctly wanted to!

3 Likes

Thank you, @meredydd and team! We appreciate you keeping Server and Uplink in sync, as much as practical.

Edit: P.S.: I just tried out v0.6.0 on some of my existing Uplink programs (Windows 10, Python v3.7). All is running well.