mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2025-06-19 08:14:16 +03:00
Add continues pull from sqlite to postgres
This commit is contained in:
parent
145cb8a19b
commit
803b6cce7c
@ -30,7 +30,15 @@ with pg_conn:
|
|||||||
with pg_conn.cursor() as cursor:
|
with pg_conn.cursor() as cursor:
|
||||||
cursor.execute(postgres_sql_requests.schema_create)
|
cursor.execute(postgres_sql_requests.schema_create)
|
||||||
|
|
||||||
with pg_conn:
|
|
||||||
|
def initial_pull_sqlite_to_postgres() -> None:
|
||||||
|
"""
|
||||||
|
Function for initial transferring data from sqlite to postgres
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
with pg_conn:
|
||||||
with pg_conn.cursor() as cursor:
|
with pg_conn.cursor() as cursor:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
@ -46,6 +54,29 @@ with pg_conn:
|
|||||||
# 149619.26856040955 ms total
|
# 149619.26856040955 ms total
|
||||||
print((time.time() - start) * 100, 'ms total')
|
print((time.time() - start) * 100, 'ms total')
|
||||||
|
|
||||||
|
|
||||||
|
def continues_pull_sqlite_to_postgres() -> None:
|
||||||
|
"""
|
||||||
|
Function to synchronize data from sqlite to postgres table
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
with pg_conn:
|
||||||
|
with pg_conn.cursor() as cursor:
|
||||||
|
cursor: psycopg2.extensions.cursor
|
||||||
|
cursor.execute('select action_id from squads_stats_states order by action_id desc limit 1;')
|
||||||
|
last_action_id_postgres: int = cursor.fetchone()[0]
|
||||||
|
|
||||||
|
new_records = sqlite_conn.execute('select * from squads_stats_states where action_id > :action_id;',
|
||||||
|
{'action_id': last_action_id_postgres}).fetchall()
|
||||||
|
|
||||||
|
cursor.executemany(insert_pg, new_records)
|
||||||
|
|
||||||
|
|
||||||
|
continues_pull_sqlite_to_postgres()
|
||||||
|
|
||||||
|
|
||||||
pg_conn.close()
|
pg_conn.close()
|
||||||
sqlite_conn.close()
|
sqlite_conn.close()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user