小编Tho*_*our的帖子

grails中withTransaction和withSession有什么区别?

我知道一个获取底层会话而另一个获取当前事务状态的引用; 但是,它们之间的区别是什么?每个用例的用例是什么?

我的要求是批量保存Service方法块中的一些记录.

session grails hibernate transactions grails-orm

14
推荐指数
1
解决办法
1万
查看次数

在sqlalchemy中为同一声明性Base使用不同的模式

我是Pyramid和SQLAlchemy的新手.我正在使用SQLAlchemy开发Python Pyramid项目.我有一个简单的模型设置如下.如何在运行时使用不同的模式?这将是一个PostgreSQL数据库后端.现在,"公共"被硬编码到声明性基础模型中.我需要能够使用不同模式的相同模型.什么是最好的方法?除非我错过了,否则SQLAlchemy的文档对我来说似乎不太清楚.

    from sqlalchemy.ext.declarative import declarative_base
    from sqlalchemy import Column, BigInteger

    __all__ = [
        "LoadTender"
    ]
    __all__.sort()

    Base = declarative_base()


    class LoadTender(Base):
        __tablename__ = "load_tenders"
        __table_args__ = {"schema": "public"}

        id = Column("pkey", BigInteger, primary_key=True)

        def __repr__(self):
            return "" % self.id
Run Code Online (Sandbox Code Playgroud)

编辑:我似乎解决了我的问题,我正在更新片段,以显示我在下面做了什么.

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, BigInteger

__all__ = [
    "LoadTender"
]
__all__.sort()

Base = declarative_base()

class ClientMixin(object):
    __table_args__ = {"schema": "client_schema_name"}


class LoadTenderMixin(object):
    __tablename__ = "load_tenders"

    id = Column("pkey", BigInteger, primary_key=True)

    def __repr__(self):
        return "" % …
Run Code Online (Sandbox Code Playgroud)

python schema sqlalchemy pyramid

11
推荐指数
1
解决办法
9232
查看次数

跨两个数据源的Grails GORM域关联

belongsTo如果其他域类使用不同的数据源,是否可以在两个域类之间建立关联(即)?这两个数据源也是不同的数据库驱动程序.

我怀疑这可能是不可能的,但我想在这里与社区联系,看看是否有可能.现在我正在尝试这样做,我得到了通常怀疑的Hibernate错误:

Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table domain_class_A refers to an unmapped class: DomainClassB

样品:

class DomainClassA {
    static belongsTo = [dcB: DomainClassB]

    static mapping = {
        datasource "ds1"
        table name: "domain_class_A", schema: "schema_A"
    }
}

class DomainClassB {
    static hasMany = [dcA: DomainClassA]

    static mapping = {
        datasource "ds2"
        table name: "domain_class_B", schema: "schema_B"
    }
}
Run Code Online (Sandbox Code Playgroud)

grails datasource grails-orm relationship

9
推荐指数
1
解决办法
4204
查看次数

将__table_args__与SQLAlchemy中的mixin类的约束相结合

在SQLAlchemy中,我已经阅读了__table_args__在声明声明时如何组合来自不同mixin的内容.

组合多个Mixins的表/映射器参数

我的问题是,这个例子说明了如何在链的末尾(MRO中的最后一个类)完成这个,但是如果我有这些Mixins并希望它出现在MyClientMixin或者Base类中,怎么会实现这个呢?避免为其他类型的mixin复制此代码?

class LaneCarrierCommitmentSummaryMixin(object):
    """ Lane Carrier Commitment Summary.

    A base class for LCCS to mixin with a client specific class.
    """

    __tablename__ = 'lane_carrier_commitment_summary'
    __table_args__ = ((UniqueConstraint(['hashmap_key', 'bow'],
                                        name='uq_lane_carrier_commitment_summary_hashmap_key_bow')),)

class MyClientMixin(object):
    """ MyClient Mixin class for providing the ETL schema. """

    __table_args__ = {'schema': 'myclient_etl'}

class MyClientLaneCarrierCommitmentSummary(LaneCarrierCommitmentSummaryMixin, DateTrackedMixin, MyClientMixin, Base):
    pass
Run Code Online (Sandbox Code Playgroud)

我对这个概念有点挣扎.

python orm sqlalchemy declarative

8
推荐指数
1
解决办法
2830
查看次数