示例#1
0
 def series(self):
     Ss = list(
         self.related_entities('books_series_link', 'book', 'series',
                               'series'))
     if Ss:
         return the(Ss)
     return None
示例#2
0
 def __getattr__(self, attr):
   k, plural = parseUC_sAttr(attr)
   if k is None:
     return self.__dict__[k]
   if plural:
     if k not in self.__M:
       return ()
     return self.__M[k]
   return the(self.__M[k])
示例#3
0
    def __getitem__(self, nodeid):
        if type(nodeid) is int or type(nodeid) is long:
            if nodeid not in self.__nodeCache:
                self.__nodeCache[nodeid] = self._newNode(nodeid)
            return self.__nodeCache[nodeid]

        if type(nodeid) is tuple:
            return the(self.nodesByNameAndType(nodeid[0], *nodeid[1:]),
                       repr(nodeid))

        raise IndexError("invalid index " + repr(nodeid))
示例#4
0
 def op_table(self, args):
   if not args:
     raise GetoptError("missing table name")
   table_name = args.pop(0)
   with Pfx(table_name):
     tbl = getattr(self.t, table_name)
     if not args:
       raise GetoptError("missing node name")
     nodename = args.pop(0)
     row = the(tbl.select(tbl.c.name == nodename).execute())
     if not args:
       for col in sorted(row.keys()):
         print("%-14s: %s" % (col, row[col]))
       return
     for arg in args:
       if '=' in arg:
         col, value = arg.split('=', 1)
         print("SET %s.%s = %s" % (nodename, col, value))
         tbl.update().where(tbl.c.name == nodename).values(**{col: value}).execute()
       else:
         col = arg
         print("%s.%s = %s" % (nodename, col, row[col]))
示例#5
0
 def __getitem__(self, id_value):
   ''' Fetch the row or rows indicated by `id_value`.
       If `id_value` is None or a string or is not slicelike or
       is not iterable return the sole matching row or raise
       IndexError.
       Otherwise return a list of row_class instances.
   '''
   cache = self._row_cache
   if id_value is None or isinstance(id_value, int):
     # direct lookup, return single row
     row = cache.get(id_value)
     if row is not None:
       return row
     row, = self.rows_where(**{self.id_column: id_value})
     return row
   if isinstance(id_value, str):
     return self.named_row(id_value, fuzzy=True)
   if isinstance(id_value, (list, set, tuple)):
     cached = {k: cache.get(k) for k in id_value}
     rows = list(filter(None, cached.values()))
     id_value = [ row for k, row in cached.items() if not row ]
     # id_value now a unique list of row keys
     if id_value:
       if len(id_value) >= 1024:
         id_value = sorted(id_value)
         offset = 0
         while offset < len(id_value):
           rows.extend(id_value[offset:offset+1024])
           offset += 1024
       else:
         condition = where_index(self.id_column, id_value)
         rows.extend(self.rows(condition.where, *condition.params))
     return rows
   condition = where_index(self.id_column, id_value)
   rows = self.rows(condition.where, *condition.params)
   if condition.is_scalar:
     return the(rows)
   return rows
示例#6
0
 def _nodeByNameAndType(self, name, *types):
     return the(self.nodesByNameAndType(name, *types), repr((name, types)))
示例#7
0
文件: db.py 项目: cameron-simpson/css
 def selectRow(self, where):
     return the(self.selectRows(where))
示例#8
0
 def rating(self):
     Rs = list(self.related_entities('books_ratings_link', 'book',
                                     'rating'))
     if Rs:
         return the(Rs).rating
     return None
示例#9
0
 def tag_by_name(self, tag_name):
     return the(T for T in self.table_tags if T.name == tag_name)
示例#10
0
 def book_by_title(self, book_title):
     return the(self.books_by_title(book_title))