def makeNewHeader(self): oldheader = self.getNestedSource().getHeader() header2 = Header() self.valueFactory = [] for i, field in enumerate(oldheader): if self.needToKeep(field.name): newfield = field.copy() newfield.name = self.rename.get(field.name, field.name) vf = self.changevalue.get(field.name, None) if isinstance(vf, str): vf = self.makeFieldEvaluator(vf) cnv = None ct = self.changetype.get(field.name, None) if ct: newtype = type(ct) if isinstance(ct, (tuple, list)): newtype, cnv = ct if isinstance(newtype, str): newtype = registry.getTypeByName(newtype) elif isinstance(ct, (type, str)): newtype = ct if isinstance(newtype, str): newtype = registry.getTypeByName(newtype) cnv = registry.getConverterByTypes( newfield.type, newtype) newfield.type = newtype vf = vf or self.makeFieldCopier(i, cnv) self.valueFactory.append(vf) header2.append(newfield) for newfield in self.newfields: vf = None if isinstance(newfield, (tuple, list)): newfield, vf = newfield if isinstance(vf, str): vf = self.makeFieldEvaluator(vf) if not callable(vf): vf = self.makeConstFactory(vf) if isinstance(newfield, (tuple, list)): newfield = Field(*newfield) elif isinstance(newfield, int): newfield = oldheader[newfield].copy() elif not isinstance(newfield, Field): newfield = Field(newfield) self.valueFactory.append(vf) header2.append(newfield) self.setHeader(header2) self.tempVars = [] for name, vf in self.temps: if isinstance(vf, str): vf = self.makeFieldEvaluator(vf) if not callable(vf): vf = self.makeConstFactory(vf) self.tempVars.append((name, vf))
class User(Base): __tablename__ = 'users' id = Field( type=Integer, primary=True, autoincrement=True, ) name = Field( type=String(100), not_null=True, ) email = Field( type=String(100), not_null=True, )
class Post(Base): __tablename__ = 'posts' id = Field( type=Integer, primary=True, autoincrement=True, ) user_id = Field( type=Integer, foreign=User.id, ) post = Field( type=String(100), not_null=False, )
def __subclass__(cls, field_types={}, **kwargs): '''Subclass this object. field_types will overlay any field_types set on this class. If field_types includes a pair (key, None), then field_types[key] will be deleted. ''' super(SchemaObj, cls).__subclass__(**kwargs) if callable(field_types): field_types = field_types(cls) cls.field_types = overlay(cls.field_types, field_types) for key, field_or_dfier in cls.field_types.iteritems(): cls.field_types[key] = Field.asfield(field_or_dfier)
def openImpl(self): self.getNestedSource().open() self.lookup.open() self.keysHeader = self.getNestedSource().getHeader().cloneByNames( self.keys or self.lookup.getKeys()) self.resultHeader = self.getNestedSource().getHeader().copy() addHeader = self.lookup.getHeader() if self.fields: addHeader = addHeader.cloneByNames(self.fields) self.resultHeader.addHeader(addHeader) if self.hitCountCol: self.resultHeader.append(Field(self.hitCountCol, int)) self.currentRow = None self.currentLookup = None self.keyCopier = FieldsCopier() self.keyCopier.makeHeaderPaths(self.getNestedSource().getHeader(), self.keysHeader) self.lookupCopier = FieldsCopier() self.lookupCopier.makeHeaderPaths(self.lookup.getHeader(), self.resultHeader) self.sourceCopier = FieldsCopier() self.sourceCopier.makeHeaderPaths(self.getNestedSource().getHeader(), self.resultHeader)
def cleateField(self, name, type_code, display_size, internal_size, precision, scale, null_ok): if type_code == None: type_code = str return Field(name, type_code, internal_size, precision)
def makeField(self): return Field(self.name, self.aggregator.t)
def __init__(self, name, start=1, count=None, step=1, stop=None): RowSource.__init__(self, Header([Field(name, type(start))])) self.rng = Range(start, count, step, stop)
def __init__(self, field_types, extra_field_policy="ignore"): super(SchemaMapping, self).__init__() self.field_types = OrderedDict() for key, field_or_dfier in field_types.iteritems(): self.field_types[key] = Field.asfield(field_or_dfier) self.extra_field_policy=extra_field_policy
def __init__(self, val_type, key_type=None): super(UniMapping, self).__init__() if key_type is None: key_type = Field(String(), not_none=True) self.key_type = Field.asfield(key_type) self.val_type = Field.asfield(val_type)
def openImpl(self): Merge.openImpl(self) if self.cols2 == None: self.cols2 = self.getHeader().listNames() self.getHeader().append(Field(self.diff, type=str, length=1)) self.order2 = Order(self.getHeader(), self.cols2)