Beispiel #1
0
def main():
    customer = Relation(Schema("Customer", "id, fname, lname, age, height"))
    customer.add(id=18392, fname="Frank", lname="Smith", age=45, height="5'8")
    customer.add(id=48921, fname="Jane", lname="Doe", age=42, height="5'6")

    print(customer)

    # output:
    #
    # Customer
    #     id      fname   lname   age     height
    #     48921   Jane    Doe     42      5'6
    #     18392   Frank   Smith   45      5'8

    print()
    print(Pi["fname", "id"](customer))

    # output:
    #
    # Customer__fname_id
    #     fname   id
    #     Frank   18392
    #     Jane    48921

    print()
    print(Sigma[lambda tup: tup.age > 43](customer))

    # output:
    #
    # Customer
    #     id      fname   lname   age     height
    #     18392   Frank   Smith   45      5'8

    print()
    print(Rho["MySchema"](Pi["fname", "id"](customer)))
Beispiel #2
0
def getRelation(table, fromName, toName):
    """ 读取关系对照表
    """
    relation = Relation(fromName, toName)
    for line in sopen(table):
        if line.startswith('#'):
            continue

        flds = line.rstrip().split()
        chs = flds[0]
        for cht in flds[1:]:
            relation.add(chs, cht)

    return relation