Skip to content

Commit

Permalink
more buildins (#39)
Browse files Browse the repository at this point in the history
* more buildins

* backups_ok

* lint

* ci
  • Loading branch information
Koos85 authored Jan 25, 2024
1 parent b0c4663 commit b0bc09c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
Expand Down
96 changes: 89 additions & 7 deletions thingsdb/client/buildin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
from typing import Union as U
from typing import Optional
from typing import Any


class Buildin:
Expand Down Expand Up @@ -208,8 +209,35 @@ async def new_collection(self, name: str):
"""
return await self.query('new_collection(name)', name=name, scope='@t')

# TODO: new module
# TODO: new node
async def new_module(
self,
name: str,
source: str,
configuration: Optional[Any] = None):
"""Creates (and configures) a new module for ThingsDB.
This function generates a change."""
return await self.query(
'new_module(name, source, configuration)',
name=name,
source=source,
configuration=configuration,
scope='@t')

async def new_node(
self,
secret: str,
name: str,
port: Optional[int] = 9220) -> int:
"""Adds a new node to ThingsDB.
This function generates a change."""
return await self.query(
'new_node(secret, name, port)',
secret=secret,
name=name,
port=port,
scope='@t')

async def new_token(
self,
Expand All @@ -221,7 +249,10 @@ async def new_token(
expiration_time = int(datetime.datetime.timestamp(expiration_time))

return await self.query(
'new_token(user, expiration_time, description)',
"""//ti
et = is_nil(expiration_time) ? nil : datetime(expiration_time);
new_token(user, et, description);
""",
user=user,
expiration_time=expiration_time,
description=description,
Expand All @@ -238,6 +269,9 @@ async def new_user(self, name: str):
"""
return await self.query('new_user(name)', name=name, scope='@t')

async def refresh_module(self, name: str):
return await self.query('refresh_module(name)', name=name, scope='@t')

async def rename_collection(
self,
collection: U[int, str],
Expand All @@ -262,7 +296,15 @@ async def rename_user(self, name: str, new_name: str) -> None:
new_name=new_name,
scope='@t')

# TODO: restore
async def restore(
self,
filename: str,
options: Optional[dict] = {}):
return await self.query(
'restore(filename, options)',
filename=filename,
options=options,
scope='@t')

async def revoke(self, target: U[int, str], user: str, mask: int):
return await self.query(
Expand All @@ -272,8 +314,25 @@ async def revoke(self, target: U[int, str], user: str, mask: int):
mask=mask,
scope='@t')

# TODO: set_module_conf
# TODO: set_module_scope
async def set_module_conf(
self,
name: str,
configuration: Optional[dict] = None):
return await self.query(
'set_module_conf(name, configuration)',
name=name,
configuration=configuration,
scope='@t')

async def set_module_scope(
self,
name: str,
scope: U[str, None]):
return await self.query(
'set_module_scope(name, module_scope)',
name=name,
module_scope=scope,
scope='@t')

async def set_password(self, user: str, new_password: str = None) -> None:
return await self.query(
Expand Down Expand Up @@ -325,6 +384,9 @@ async def backup_info(self, backup_id: int, scope='@n'):
async def backups_info(self, scope='@n') -> list:
return await self.query('backups_info()', scope=scope)

async def backups_ok(self, scope='@n') -> bool:
return await self.query('backups_ok()', scope=scope)

async def counters(self, scope='@n'):
return await self.query('counters()', scope=scope)

Expand All @@ -342,7 +404,27 @@ async def del_backup(
async def has_backup(self, backup_id: int, scope='@n'):
return await self.query('has_backup(id)', id=backup_id, scope=scope)

# TODO: new_backup
async def new_backup(
self,
file_template: str,
start_ts: Optional[datetime.datetime] = None,
repeat: Optional[int] = 0,
max_files: Optional[int] = 7,
scope='@n'):

if start_ts is not None:
start_ts = int(datetime.datetime.timestamp(start_ts))

return await self.query(
"""//ti
start_ts = is_nil(start_ts) ? nil : datetime(start_ts);
new_backup(file_template, start_ts, repeat, max_files);
""",
file_template=file_template,
start_ts=start_ts,
repeat=repeat,
max_files=max_files,
scope=scope)

async def node_info(self, scope='@n') -> dict:
return await self.query('node_info()', scope=scope)
Expand Down

0 comments on commit b0bc09c

Please sign in to comment.