Alexander
TrackedDict has method get_untracked
Alexander
You can see db.last_sql for last executed query, but currently there is no method to see SQL before execution. I'll add it #todo
Genesis Shards Community
hi, one question
class Prestamoscab(db.Entity):
idprestamo = PrimaryKey(int, auto=True)
estado = Required(int, 1)
Genesis Shards Community
Genesis Shards Community
Genesis Shards Community
cual sería la solución?
Jim
use keyword argument for your "1" parameter. it's ok with string (for max length) but not for int
Alexander
In traceback I see
estado = Required(int(1))
it probably should be
estado = Required(int, default=1)
Lucky
Alexander
yes
Genesis Shards Community
Person.select(lambda c: c.id == 23)
ó
select(p for p in Person if p.id == 23)
Genesis Shards Community
exist: Entity.get().limit(1) ?
Jim
Person[23]
Genesis Shards Community
hi, help me
Genesis Shards Community
pony.orm.core.MultipleObjectsFoundError: Multiple objects were found. Use select(...) to retrieve them
Genesis Shards Community
comision = Comision.get(lambda c: c.cantidad_1 <= Decimal(_importe) and c.cantidad_2 >=Decimal(_importe) and c.idagencia.idagencia == 1).limit(1)
М
You have more, than one object in db. Use select instead of get
Anonymous
When using customer1 = Customer["aBc"] to select an entity by it's primary key is that select performed case-sensitive? (sqlite)? I have PRAGMA case_sensitive_like = OFF but I'm not sure if that's relevant when selecting as shown above / using the primary key
Alexander
it uses =, not LIKE. so case_sensitive_like is not relevant
Assuming primary key column named pk, you can write
x = 'aBc'
customer = Customer.get(lambda c: raw_sql("c.pk LIKE $x"))
Anonymous
thanks, good to know! for now I'm just using lower() on the key before creating an entity and lower() inside a wrapper I use for comparing. it works fine but I was wondering if it was necessary at all.
Anonymous
Another question that came up recently: can I use magic methods within an Entity class? Does that make much sense? E.g.:
class BaseModel(db.Entity):
uuid = PrimaryKey(str, auto=False)
data = Required(Json)
def __repr__(self):
return str(json.dumps(self.data))
def __hash__(self):
return str(self.uuid.lower())
Anonymous
Or would that interfere with any internals used by ponyorm?
Alexander
Alexander
Anonymous
Thanks! Will remove __hash__ then 😊
Anonymous
I searched the API docs but couldn't find anything about this: what exception is raised if a attrbute of an model is set to unique and one tries to add two entities with the same attribute?
Anonymous
nevermind, just tried it: pony.orm.core.CacheIndexError
Anonymous
and pony.orm.core.TransactionIntegrityError I guess
Jorge
Hello! Wich is the current state for managing migrations with ponyorm?
Alexander
Migration support is 90% ready, but not released yet
Jorge
Migration support is 90% ready, but not released yet
Wow awesome!! And there is an alternative or temporal workaround to have migrations? I bassically ask this to know which is the best way to manage files migrations, an official recomendation or anything else
Alexander
You can try branch orm-migrations with previous attempt to migrations:
https://github.com/ponyorm/pony/tree/orm-migrations/pony/migrate
It should work for simple cases
Permalink Bot
Jorge
Alexander
You can also try tool written by @luckydonald
https://github.com/luckydonald/pony_up
Permalink Bot
Jorge
Lucky
Lucky
Lucky
@admins spam
Xavier
There is any way to install an own instance of the online editor?
Alexey
Abuelazo
hola necesito resolver una duda
tengo una tabla cotizaciones con los siguientes campos
class Cotizacion(db.Entity):
idcotizacion = PrimaryKey(int, auto=True)
fecha = Optional(date)
total = Optional(str)
observaciones = Optional(LongStr)
cliente = Required(Cliente)
log = Optional(datetime, default=lambda: datetime.now())
status = Required(int)
cuando realizo un select obtengo todos los datos meno observaciones
mi consulta es la siguiente
resultado = select(c for c in tabla.Cotizacion)[:]
y lo que obtengo es esto
idcotizacion|fecha |total |cliente |log |status
------------+----------+-------+----------+-------------------+------
1 |2019-12-04|20840.0|Cliente[1]|2019-12-04 14:56:07|1
alguien podria decirme porque omite el campo observaciones?
Jonah
Hi folks. Loving pony! I have a devops scenario where postGREST must access the db pony generates by way of a schema. How would I tell pony to use a schema when creating the mappings ?
Alexander
Jonah
``
Jonah
how do you put code in the markup here ?
Jonah
`import sys
import sys, inspect
def print_classes():
for name, obj in inspect.getmembers(sys.modules[__name__]):
if inspect.isclass(obj) and obj.__class__ == pony.orm.core.EntityMeta:
obj._table_ = ('api', obj.__name__.lower())'
Alexander
three backquotes, or righ-click selected text
Jonah
import sys
import sys, inspect
def print_classes():
for name, obj in inspect.getmembers(sys.modules[__name__]):
if inspect.isclass(obj) and obj.__class__ == pony.orm.core.EntityMeta:
obj._table_ = ('api', obj.__name__.lower())
Jonah
is this sufficient / correct ?
Alexander
hmm
Jonah
I'm pasting the definitions from the graphical editor
Jonah
then looping through the classes as defined on the page
Jonah
then adding the schema I need for postgrest
Alexander
It looks a bit hacky, but if you do it before calling db.generate_mapping() it probably should work
Jonah
Yah well I'm used to metaclasses so I feel at home
Jonah
Pony is amazing. What is the timeline for migrations ?
Alexander
Pony creates additional structures inside entity, so it may be dangerous to modify some options after entity creation, as internal fields will not be updated correspondingly. But it seems entity._table_ does not used before db.generate_mapping(), so it should work
Jonah
I see. Good to know
Jonah
Also good news!
Jonah
@metaprogrammer that worked "like butta" I just had to use db.generate_mapping(create_tables=True) after looping through/modifying the definitions
Jonah
scratch that - it didn't create the data in the api schema 🙂
Jonah
🙁
Alexander
You cannot call generate_mapping several times
Jonah
oddly neither work. even when used just once.
Jonah
class BillingCode(db.Entity):
_table_ = [schema, "billingcode"]
id = PrimaryKey(int, auto=True)
code_id = Optional(str)
visits = Set(Visit)
Alexander
works fine for me:
Jonah
@metaprogrammer everything fails when using the schema I create. Does pony need to create the schema ?
Alexander
from pony.orm import *
db = Database()
class Foo(db.Entity):
name = Required(str)
Foo._table_ = ('myschema', 'mytable')
db_params = dict(provider='postgres', user='pony', password='pony', host='localhost', database='pony')
db.bind(**db_params)
db.generate_mapping(create_tables=True)
with db_session:
Foo(name='x')
Foo(name='y')
Jonah
ok let me try this!
Alexander
(I created "myschema" schema inside "pony" database manually and set "pony" user as owner so it has rights to create tables inside)
Alexander
Pony does not create schema itself, it expects it already had been created
Jonah
@metaprogrammer that worked
Abuelazo
Luis
👍