コード例 #1
0
ファイル: model.py プロジェクト: fredvdd/Swan
	def __getattribute__(self, name):
			try:
				# print "Get %s attr from %s" % (name, object.__getattribute__(self, '__class__'))
				if name not in ['__repr__','__len__', '__iter__', '__getitem__']:
					return object.__getattribute__(self, name)
				else:
					raise AttributeError
			except AttributeError:
				it = object.__getattribute__(self,'instance_type')
				if hasattr(it,name) or it.__dict__['__fields'].has_key(name):
					if it.__dict__.has_key(name) and isinstance(it.__dict__[name], ForeignRelation):
						return RelationSet(it.__dict__[name],object.__getattribute__(self, 'model'), object.__getattribute__(self,'model_type'), **object.__getattribute__(self, 'filters'))
				if not object.__getattribute__(self, 'cached'):
					log.debug(None, "Getting cache for %s access" % name)
					object.__getattribute__(self, '_check_cache')()
					# object.__setattr__(self, 'cache', object.__getattribute__(self, 'evaluate')())
					# object.__setattr__(self, 'cached', True)
					return getattr(object.__getattribute__(self,'cache'),name)
コード例 #2
0
ファイル: model.py プロジェクト: fredvdd/Swan
	def execute_insert(self, query):
		log.debug(self, "Executing SQL: " + query)
		cursor = self.workers.one().get_cursor()
		cursor.execute(query)
		return cursor.lastrowid()
コード例 #3
0
ファイル: model.py プロジェクト: fredvdd/Swan
	def execute_select(self, desc, query):
		log.debug(self, "Executing SQL: " + query)
		cursor = self.workers.one().get_cursor().execute(query)
		rows = cursor.fetchall()
		props = [dict(zip(desc,row))for row in rows]
		return [self.model_instance(self, self.__class__, **ps) for ps in props]