Skip to content

Commit b0bc09c

Browse files
authored
more buildins (#39)
* more buildins * backups_ok * lint * ci
1 parent b0c4663 commit b0bc09c

File tree

2 files changed

+91
-9
lines changed

2 files changed

+91
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515
- name: Set up Python 3.9
16-
uses: actions/setup-python@v2
16+
uses: actions/setup-python@v5
1717
with:
1818
python-version: 3.9
1919
- name: Install dependencies

thingsdb/client/buildin.py

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
from typing import Union as U
33
from typing import Optional
4+
from typing import Any
45

56

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

211-
# TODO: new module
212-
# TODO: new node
212+
async def new_module(
213+
self,
214+
name: str,
215+
source: str,
216+
configuration: Optional[Any] = None):
217+
"""Creates (and configures) a new module for ThingsDB.
218+
219+
This function generates a change."""
220+
return await self.query(
221+
'new_module(name, source, configuration)',
222+
name=name,
223+
source=source,
224+
configuration=configuration,
225+
scope='@t')
226+
227+
async def new_node(
228+
self,
229+
secret: str,
230+
name: str,
231+
port: Optional[int] = 9220) -> int:
232+
"""Adds a new node to ThingsDB.
233+
234+
This function generates a change."""
235+
return await self.query(
236+
'new_node(secret, name, port)',
237+
secret=secret,
238+
name=name,
239+
port=port,
240+
scope='@t')
213241

214242
async def new_token(
215243
self,
@@ -221,7 +249,10 @@ async def new_token(
221249
expiration_time = int(datetime.datetime.timestamp(expiration_time))
222250

223251
return await self.query(
224-
'new_token(user, expiration_time, description)',
252+
"""//ti
253+
et = is_nil(expiration_time) ? nil : datetime(expiration_time);
254+
new_token(user, et, description);
255+
""",
225256
user=user,
226257
expiration_time=expiration_time,
227258
description=description,
@@ -238,6 +269,9 @@ async def new_user(self, name: str):
238269
"""
239270
return await self.query('new_user(name)', name=name, scope='@t')
240271

272+
async def refresh_module(self, name: str):
273+
return await self.query('refresh_module(name)', name=name, scope='@t')
274+
241275
async def rename_collection(
242276
self,
243277
collection: U[int, str],
@@ -262,7 +296,15 @@ async def rename_user(self, name: str, new_name: str) -> None:
262296
new_name=new_name,
263297
scope='@t')
264298

265-
# TODO: restore
299+
async def restore(
300+
self,
301+
filename: str,
302+
options: Optional[dict] = {}):
303+
return await self.query(
304+
'restore(filename, options)',
305+
filename=filename,
306+
options=options,
307+
scope='@t')
266308

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

275-
# TODO: set_module_conf
276-
# TODO: set_module_scope
317+
async def set_module_conf(
318+
self,
319+
name: str,
320+
configuration: Optional[dict] = None):
321+
return await self.query(
322+
'set_module_conf(name, configuration)',
323+
name=name,
324+
configuration=configuration,
325+
scope='@t')
326+
327+
async def set_module_scope(
328+
self,
329+
name: str,
330+
scope: U[str, None]):
331+
return await self.query(
332+
'set_module_scope(name, module_scope)',
333+
name=name,
334+
module_scope=scope,
335+
scope='@t')
277336

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

387+
async def backups_ok(self, scope='@n') -> bool:
388+
return await self.query('backups_ok()', scope=scope)
389+
328390
async def counters(self, scope='@n'):
329391
return await self.query('counters()', scope=scope)
330392

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

345-
# TODO: new_backup
407+
async def new_backup(
408+
self,
409+
file_template: str,
410+
start_ts: Optional[datetime.datetime] = None,
411+
repeat: Optional[int] = 0,
412+
max_files: Optional[int] = 7,
413+
scope='@n'):
414+
415+
if start_ts is not None:
416+
start_ts = int(datetime.datetime.timestamp(start_ts))
417+
418+
return await self.query(
419+
"""//ti
420+
start_ts = is_nil(start_ts) ? nil : datetime(start_ts);
421+
new_backup(file_template, start_ts, repeat, max_files);
422+
""",
423+
file_template=file_template,
424+
start_ts=start_ts,
425+
repeat=repeat,
426+
max_files=max_files,
427+
scope=scope)
346428

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

0 commit comments

Comments
 (0)