Package gluon :: Module dal :: Class Rows
[hide private]
[frames] | no frames]

Class Rows

source code

object --+
         |
        Rows

A wrapper for the return value of a select. It basically represents a table. It has an iterator and each row is represented as a dictionary.

Instance Methods [hide private]
 
__init__(self, db=None, records=[], colnames=[], compact=True, rawrows=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__repr__(self)
repr(x)
source code
 
setvirtualfields(self, **keyed_virtualfields)
db.define_table('x',Field('number','integer')) if db(db.x).isempty(): [db.x.insert(number=i) for i in range(10)]
source code
 
__and__(self, other) source code
 
__or__(self, other) source code
 
__nonzero__(self) source code
 
__len__(self) source code
 
__getslice__(self, a, b) source code
 
__getitem__(self, i) source code
 
__iter__(self)
iterator over records
source code
 
__str__(self)
serializes the table into a csv file
source code
 
first(self) source code
 
last(self) source code
 
find(self, f, limitby=None)
returns a new Rows object, a subset of the original object, filtered by the function f
source code
 
exclude(self, f)
removes elements from the calling Rows object, filtered by the function f, and returns a new Rows object containing the removed elements
source code
 
sort(self, f, reverse=False)
returns a list of sorted elements (not sorted in place)
source code
 
group_by_value(self, *fields, **args)
regroups the rows, by one of the fields
source code
 
render(self, i=None, fields=None)
Takes an index and returns a copy of the indexed row with values transformed via the "represent" attributes of the associated fields.
source code
 
as_list(self, compact=True, storage_to_dict=True, datetime_to_str=False, custom_types=None)
returns the data as a list or dictionary.
source code
 
as_dict(self, key='id', compact=True, storage_to_dict=True, datetime_to_str=False, custom_types=None)
returns the data as a dictionary of dictionaries (storage_to_dict=True) or records (False)
source code
 
as_trees(self, parent_name='parent_id', children_name='children') source code
 
export_to_csv_file(self, ofile, null='<NULL>', *args, **kwargs)
export data to csv, the first line contains the column names
source code
 
xml(self, strict=False, row_name='row', rows_name='rows')
serializes the table using sqlhtml.SQLTABLE (if present)
source code
 
as_xml(self, row_name='row', rows_name='rows') source code
 
as_json(self, mode='object', default=None)
serializes the rows to a JSON list or object with objects mode='object' is not implemented (should return a nested object structure)
source code
 
as_csv(self)
serializes the table into a csv file
source code
 
json(self, mode='object', default=None)
serializes the rows to a JSON list or object with objects mode='object' is not implemented (should return a nested object structure)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, db=None, records=[], colnames=[], compact=True, rawrows=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

setvirtualfields(self, **keyed_virtualfields)

source code 

db.define_table('x',Field('number','integer'))
if db(db.x).isempty(): [db.x.insert(number=i) for i in range(10)]

from gluon.dal import lazy_virtualfield

class MyVirtualFields(object):
    # normal virtual field (backward compatible, discouraged)
    def normal_shift(self): return self.x.number+1
    # lazy virtual field (because of @staticmethod)
    @lazy_virtualfield
    def lazy_shift(instance,row,delta=4): return row.x.number+delta
db.x.virtualfields.append(MyVirtualFields())

for row in db(db.x).select():
    print row.number, row.normal_shift, row.lazy_shift(delta=7)

__str__(self)
(Informal representation operator)

source code 

serializes the table into a csv file

Overrides: object.__str__

render(self, i=None, fields=None)

source code 

Takes an index and returns a copy of the indexed row with values
transformed via the "represent" attributes of the associated fields.

If no index is specified, a generator is returned for iteration
over all the rows.

fields -- a list of fields to transform (if None, all fields with
          "represent" attributes will be transformed).

as_list(self, compact=True, storage_to_dict=True, datetime_to_str=False, custom_types=None)

source code 

returns the data as a list or dictionary. :param storage_to_dict: when True returns a dict, otherwise a list(default True) :param datetime_to_str: convert datetime fields as strings (default False)

as_dict(self, key='id', compact=True, storage_to_dict=True, datetime_to_str=False, custom_types=None)

source code 

returns the data as a dictionary of dictionaries (storage_to_dict=True) or records (False)

:param key: the name of the field to be used as dict key, normally the id :param compact: ? (default True) :param storage_to_dict: when True returns a dict, otherwise a list(default True) :param datetime_to_str: convert datetime fields as strings (default False)

export_to_csv_file(self, ofile, null='<NULL>', *args, **kwargs)

source code 

export data to csv, the first line contains the column names

:param ofile: where the csv must be exported to
:param null: how null values must be represented (default '<NULL>')
:param delimiter: delimiter to separate values (default ',')
:param quotechar: character to use to quote string values (default '"')
:param quoting: quote system, use csv.QUOTE_*** (default csv.QUOTE_MINIMAL)
:param represent: use the fields .represent value (default False)
:param colnames: list of column names to use (default self.colnames)
                 This will only work when exporting rows objects!!!!
                 DO NOT use this with db.export_to_csv()