def test(self):
     engine = engine_creator.create_sqlite()
     collector = StatsCollector(engine=engine)
     assert len(collector._cache_apikey) == 0
     collector.add_all_apikey(
         [GoogleMapApiKey(apikey=apikey) for apikey in apikeys]
     )
     assert len(collector._cache_apikey) == 4
    def __init__(self, data):
        self.engine = engine_creator.create_sqlite()
        self.metadata = MetaData()
        self.table = Table(
            "user",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("name", String, index=True),
        )
        self.metadata.create_all(self.engine)

        self.engine.execute(self.table.insert(), data)
def collector():
    engine = engine_creator.create_sqlite()
    collector = StatsCollector(engine=engine)
    collector.add_all_apikey(
        [GoogleMapApiKey(apikey=apikey) for apikey in apikeys]
    )

    status_id_list = StatusCollection.get_id_list()
    for _ in range(100):
        primary_key = random.choice(apikeys)
        status_id = random.choice(status_id_list)
        collector.add_event(primary_key, status_id)
    return collector
示例#4
0
    def __init__(self, apikey_list, reach_limit_exc=None, db_engine=None):
        # validate
        for apikey in apikey_list:
            validate_is_apikey(apikey)

        # stats collector
        if db_engine is None:
            db_engine = engine_creator.create_sqlite()

        self.stats = StatsCollector(engine=db_engine)
        self.stats.add_all_apikey(apikey_list)

        # initiate apikey chain data
        self.apikey_chain = OrderedDict()
        for apikey in apikey_list:
            self.add_one(apikey, upsert=False)

        self.archived_apikey_chain = OrderedDict()

        if reach_limit_exc is None:
            reach_limit_exc = NeverRaisesError
        self.reach_limit_exc = reach_limit_exc
        self.dummyclient = DummyClient()
        self.dummyclient._apikey_manager = self
def engine():
    return engine_creator.create_sqlite()
# -*- coding: utf-8 -*-
"""
.. note::

    session + text sql doesn't work.
"""

from sqlalchemy import text
from sqlalchemy_mate import engine_creator

from learn_datasette.datamodel import Movie
from s1_make_data import db_file

engine = engine_creator.create_sqlite(db_file)

sql = text("""
SELECT * 
FROM movie
WHERE rowid in 
(
    SELECT rowid 
    FROM movie_fts 
    WHERE movie_fts 
    MATCH 'man'
) 
ORDER BY id 
LIMIT 101
""")
movie_columns = [c.name for c in Movie.__table__._columns]
for row in engine.execute(sql):
    movie = Movie(**dict(zip(movie_columns, row)))
示例#7
0
def create_in_memory():
    return engine_creator.create_sqlite()
示例#8
0
def create_local_file():
    return engine_creator.create_sqlite(dbpath)
# -*- coding: utf-8 -*-

from sqlalchemy_mate import engine_creator

engine = engine_creator.create_sqlite()