在下面的示例中,当我再次调用 School.get(1) 时,学校模型有一个唯一的字段“key”。不会有任何查询,这很好。但是当调用 School.get_by_key('gxu') 查询调用时。
我想要的是,因为“key”是独一无二的,所以 SQLALchemy 可以聪明地不再查询吗?
In [3]: school = School.get(1)
INFO-2013-06-14 18:08:17,903:BEGIN (implicit)
INFO-2013-06-14 18:08:17,904:SELECT school_info._id AS school_info__id, school_info."key" AS school_info_key, school_info.name AS school_info_name
FROM school_info
WHERE school_info._id = ?
INFO-2013-06-14 18:08:17,905:(1,)
DEBUG-2013-06-14 18:08:17,906:Col ('school_info__id', 'school_info_key', 'school_info_name')
DEBUG-2013-06-14 18:08:17,906:Row (1, u'gxu', u'\u5e7f\u897f\u5927\u5b66')
In [4]: gxu_school = School.get_by_key('gxu')
INFO-2013-06-14 18:08:32,042:SELECT school_info._id AS school_info__id, school_info."key" AS school_info_key, school_info.name AS school_info_name
FROM school_info
WHERE school_info."key" = ?
LIMIT ? OFFSET ?
INFO-2013-06-14 18:08:32,045:(u'gxu', 1, 0)
DEBUG-2013-06-14 18:08:32,046:Col ('school_info__id', 'school_info_key', 'school_info_name')
DEBUG-2013-06-14 18:08:32,047:Row (1, u'gxu', u'\u5e7f\u897f\u5927\u5b66')
In [5]: