forked from lAmeR1/kaspa-socket-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KeyValueStore in PostgreSQL added. (#22)
hashrate/max with Cache via KeyValueStore.
- Loading branch information
Showing
3 changed files
with
64 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# encoding: utf-8 | ||
from sqlalchemy import select, update, insert | ||
|
||
from dbsession import async_session | ||
from models.Variable import KeyValueModel | ||
|
||
|
||
async def get(key): | ||
async with async_session() as s: | ||
result = await s.execute(select(KeyValueModel.value).where(KeyValueModel.key == key)) | ||
return result.scalar() | ||
|
||
|
||
async def set(key, value): | ||
async with async_session() as s: | ||
result = await s.execute(update(KeyValueModel) | ||
.where(KeyValueModel.key == key) | ||
.values(value=value)) | ||
|
||
if result.rowcount == 1: | ||
await s.commit() | ||
return True | ||
|
||
result = await s.execute(insert(KeyValueModel).values(key=key, value=value)) | ||
|
||
await s.commit() | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from sqlalchemy import Column, String, Text | ||
|
||
from dbsession import Base | ||
|
||
|
||
class KeyValueModel(Base): | ||
__tablename__ = 'vars' | ||
key = Column(String, primary_key=True) | ||
value = Column(Text) |