为什么这里的select语句包含MyDynamicTable
而不是from peewee import *
database = SqliteDatabase(None)
class Base(Model):
class Meta:
database = database
class MyTable(Base):
FieldA = TextField()
FieldB = TextField()
mytable = type('MyDynamicTable', (MyTable,), {})
database.init('test.db')
mytable.select()
?
>>> mytable.select()
<class 'peewee.MyDynamicTable'> SELECT "t1"."id", "t1"."FieldA", "t1"."FieldB" FROM "mydynamictable" AS t1 []
导致:
>>> mytable
<class 'peewee.MyDynamicTable'>
>>> mytable._meta.db_table
'mydynamictable'
但名字是正确的:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ whereis xcrun
/usr/bin/xcrun
答案 0 :(得分:1)
Peewee给你的桌名别名。如果您阅读完整查询:
SELECT "t1"."id", "t1"."FieldA", "t1"."FieldB"
FROM "mydynamictable" AS t1
&#34; mydynamictable&#34; AS t1 部分将表名别名为&#34; t1&#34;,以使查询更紧凑。当您有连接并且需要消除具有相同名称的列的歧义时,这一点尤为重要。