Project

General

Profile

« Previous | Next » 

Revision 2818

sql_gen.py: TypedCol: Added default and nullable params

View differences:

sql_gen.py
528 528
##### Database structure
529 529

  
530 530
class TypedCol(Col):
531
    def __init__(self, name, type_):
531
    def __init__(self, name, type_, default=None, nullable=True):
532
        assert default == None or isinstance(default, Code)
533
        
532 534
        Col.__init__(self, name)
533 535
        
534 536
        self.type = type_
537
        self.default = default
538
        self.nullable = nullable
535 539
    
536
    def to_str(self, db): return Col.to_str(self, db)+' '+self.type
540
    def to_str(self, db):
541
        str_ = Col.to_str(self, db)+' '+self.type
542
        if not self.nullable: str_ += ' NOT NULL'
543
        if self.default != None: str_ += ' DEFAULT '+self.default.to_str(db)
544
        return str_
537 545
    
538 546
    def to_Col(self): return Col(self.name)

Also available in: Unified diff