示例#1
0
        class SomeClass(TableModel):
            __tablename__ = 'some_class'

            id = Integer32(primary_key=True)

            children = Array(
                SomeChildClass,
                store_as=table(
                    multi='children',
                    lazy='joined',
                    left='parent_id',
                    right='child_id',
                    fk_left_ondelete='cascade',
                    fk_right_ondelete='cascade',
                ),
            )

            other_children = Array(
                SomeOtherChildClass,
                store_as=table(
                    multi='children',
                    lazy='joined',
                    left='parent_id',
                    right='other_child_id',
                    fk_left_ondelete='cascade',
                    fk_right_ondelete='cascade',
                ),
            )
示例#2
0
        class SomeClass(TableModel):
            __tablename__ = 'some_class'
            __table_args__ = {"sqlite_autoincrement": True}

            id = Integer32(primary_key=True)
            others = Array(SomeOtherClass,
                           store_as=table(multi=True, backref='some_classes'))
示例#3
0
文件: db.py 项目: mfkaptan/spynepi
class Package(TableModel):
    __tablename__ = "%s_package" % TABLE_PREFIX
    __table_args__ = (
        (UniqueConstraint("package_name"), ),
        {
            "sqlite_autoincrement": True
        },
    )

    id = Integer32(primary_key=True)
    rdf_about = Unicode(256)
    package_name = String(40)
    package_cdate = Date
    package_description = Unicode
    package_license = Unicode(256)
    package_home_page = String(256)

    owners = Array(Person).store_as(table(right="owner_id"))
    releases = Array(Release).store_as(table(right="package_id"))
示例#4
0
文件: db.py 项目: mfkaptan/spynepi
class Release(TableModel):
    __tablename__ = "%s_release" % TABLE_PREFIX
    __table_args__ = {"sqlite_autoincrement": True}

    id = Integer32(primary_key=True)
    release_cdate = Date
    rdf_about = String(256)
    release_version = String(10)
    meta_version = String(10)
    release_summary = String(256)
    release_platform = String(30)

    distributions = Array(Distribution).store_as(table(right="release_id"))
示例#5
0
    def test_append_field_array_many(self):
        class C(TableModel):
            __tablename__ = "c"
            id = Integer32(pk=True)

        class D(TableModel):
            __tablename__ = "d"
            id = Integer32(pk=True)

        C.append_field('d', Array(D).store_as(table(multi='c_d')))
        assert C.Attributes.sqla_mapper.get_property('d').argument is D
        rel_table = C.Attributes.sqla_metadata.tables['c_d']
        assert 'c_id' in rel_table.c
        assert 'd_id' in rel_table.c
示例#6
0
    def test_append_field_array_many(self):
        class C(TableModel):
            __tablename__ = "c"
            id = Integer32(pk=True)

        class D(TableModel):
            __tablename__ = "d"
            id = Integer32(pk=True)

        C.append_field('d', Array(D).store_as(table(multi='c_d')))
        assert C.Attributes.sqla_mapper.get_property('d').argument is D
        rel_table = C.Attributes.sqla_metadata.tables['c_d']
        assert 'c_id' in rel_table.c
        assert 'd_id' in rel_table.c
示例#7
0
    def test_append_field_complex_cust(self):
        class C(TableModel):
            __tablename__ = "c"
            id = Integer32(pk=True)

        class D(TableModel):
            __tablename__ = "d"
            id = Integer32(pk=True)
            c = Array(C).store_as('table')

        C.append_field('d', D.customize(
            nullable=False,
            store_as=table(left='d_id'),
        ))
        assert C.__table__.c['d_id'].nullable == False
示例#8
0
    def test_append_field_complex_cust(self):
        class C(TableModel):
            __tablename__ = "c"
            id = Integer32(pk=True)

        class D(TableModel):
            __tablename__ = "d"
            id = Integer32(pk=True)
            c = Array(C).store_as('table')

        C.append_field('d', D.customize(
            nullable=False,
            store_as=table(left='d_id'),
        ))
        assert C.__table__.c['d_id'].nullable == False
示例#9
0
    def test_append_field_complex_circular_array(self):
        class C(TableModel):
            __tablename__ = "cc"
            id = Integer32(pk=True)

        class D(TableModel):
            __tablename__ = "dd"
            id = Integer32(pk=True)
            c = Array(C).customize(store_as=table(right='dd_id'))

        C.append_field('d', D.customize(store_as=table(left='dd_id')))
        self.metadata.create_all()

        c1, c2 = C(id=1), C(id=2)
        d = D(id=1, c=[c1, c2])
        self.session.add(d)
        self.session.commit()
        assert c1.d.id == 1
示例#10
0
    def test_append_field_complex_circular_array(self):
        class C(TableModel):
            __tablename__ = "cc"
            id = Integer32(pk=True)

        class D(TableModel):
            __tablename__ = "dd"
            id = Integer32(pk=True)
            c = Array(C).customize(store_as=table(right='dd_id'))

        C.append_field('d', D.customize(store_as=table(left='dd_id')))
        self.metadata.create_all()

        c1, c2 = C(id=1), C(id=2)
        d = D(id=1, c=[c1, c2])
        self.session.add(d)
        self.session.commit()
        assert c1.d.id == 1
示例#11
0
 class D(TableModel):
     __tablename__ = "dd"
     id = Integer32(pk=True)
     c = Array(C).customize(store_as=table(right='dd_id'))