예제 #1
0
    class Model(BaseModel):
        id = Column(Integer, hash_key=True)
        foo = Column(Integer)
        bar = Column(Integer)
        baz = Column(Integer)

        by_foo = GlobalSecondaryIndex(projection=["foo"],
                                      hash_key=bar,
                                      range_key="baz")
        by_bar = GlobalSecondaryIndex(projection=[foo],
                                      hash_key="bar",
                                      range_key=baz)
예제 #2
0
 class MyModel(BaseModel):
     class Meta:
         read_units = 1
         write_units = 1
     id = Column(String, hash_key=True)
     other = Column(String)
     by_other = GlobalSecondaryIndex(projection="keys", hash_key=other)
예제 #3
0
파일: test_engine.py 프로젝트: xuru/bloop
    class Abstract(BaseModel):
        class Meta:
            abstract = True

        id = Column(Integer, hash_key=True)
        other = Column(Integer)
        by_other = GlobalSecondaryIndex(projection="all", hash_key="other")
예제 #4
0
    class Model(BaseModel):
        id = Column(UUID, hash_key=True)
        other = Column(DateTime, range_key=True)
        another = Column(UUID)
        last = Column(String)

        by_last = GlobalSecondaryIndex(hash_key="another",
                                       range_key="last",
                                       projection="keys")
        by_another = LocalSecondaryIndex(range_key="last", projection="keys")
예제 #5
0
    class Model(BaseModel):
        id = Column(UUID, hash_key=True)
        other = Column(UUID, range_key=True)
        another = Column(UUID)
        date = Column(DateTime)
        boolean = Column(Boolean)

        g_all = GlobalSecondaryIndex(hash_key="another",
                                     range_key="date",
                                     projection="all")
        g_key = GlobalSecondaryIndex(hash_key="another", projection="keys")
        g_inc = GlobalSecondaryIndex(hash_key="other",
                                     projection=["another", "date"])

        l_all = LocalSecondaryIndex(range_key="another", projection="all")
        l_key = LocalSecondaryIndex(range_key="another", projection="keys")
        l_inc = LocalSecondaryIndex(range_key="another", projection=["date"])
        l_not_strict = LocalSecondaryIndex(range_key="another",
                                           projection=["date"],
                                           strict=False)
예제 #6
0
def model_for(has_model_range=False,
              has_index=False,
              has_index_range=False,
              index_type="gsi",
              index_projection="all",
              strict=True):
    """Not all permutations are possible.  Impossible selections will always self-correct.

    For instance, has_model_range=False, has_index=True, index_type="gsi" can't happen.
    Instead, the model won't have an index."""
    model_range_ = None
    index_hash_ = None
    index_range_ = None
    by_index_ = None

    if has_model_range:
        model_range_ = Column(Integer, range_key=True)
    # Sets up index_hash, index_range, by_index
    if has_index:
        if index_type == "gsi":
            index_hash_ = Column(Integer)
            if has_index_range:
                index_range_ = Column(Integer)
            by_index_ = GlobalSecondaryIndex(
                projection=index_projection,
                hash_key="index_hash",
                range_key="index_range" if has_index_range else None)
        elif index_type == "lsi" and has_model_range and has_index_range:
            index_range_ = Column(Integer)
            by_index_ = LocalSecondaryIndex(projection=index_projection,
                                            range_key="index_range",
                                            strict=strict)

    class TestModel(BaseModel):
        # Included in an "all" projection, not "keys"
        not_projected = Column(Integer)
        # Included in "include" projections
        inc = Column(Integer)

        model_hash = Column(Integer, hash_key=True)
        model_range = model_range_
        index_hash = index_hash_
        index_range = index_range_
        by_index = by_index_

    return TestModel, by_index_
예제 #7
0
def test_gsi_repr():
    index = GlobalSecondaryIndex(projection="all", hash_key="key", name="f")
    index.model = User
    index.model_name = "by_foo"
    assert repr(index) == "<GSI[User.by_foo=all]>"
예제 #8
0
 class Model(BaseModel):
     name = Column(String, hash_key=True)
     other = Column(String)
     by_joined = GlobalSecondaryIndex(hash_key="other", projection="keys")
예제 #9
0
 class Model(BaseModel):
     id = Column(Integer, hash_key=True)
     other = Column(Integer)
     by_other = GlobalSecondaryIndex(projection="all", hash_key="other")