Skip to content

Commit

Permalink
adding DB snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellflitton committed Jan 15, 2025
1 parent d72ffcc commit 782d05f
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ clog/
manifest/
.mypy_cache/
.ruff_cache/
tests/db_snapshots/
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ services:
ports:
- 8000:8000

surrealdb_big_data:
image: surrealdb/surrealdb:v2.0.0
command: "start"
environment:
- SURREAL_USER=root
- SURREAL_PASS=root
- SURREAL_LOG=trace
ports:
- 8300:8000
volumes:
- ./tests/db_snapshots/data/:/data/

surrealdb_200:
image: surrealdb/surrealdb:v2.0.0
command: "start"
Expand Down
15 changes: 15 additions & 0 deletions scripts/download_snapshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# navigate to directory
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
cd $SCRIPTPATH

cd ..
cd tests

if [ -d "./db_snapshots" ]; then
echo "DB snapshots are already present"
rm -rf ./db_snapshots
fi

dockpack pull -i maxwellflitton/surrealdb-data -d ./db_snapshots
8 changes: 4 additions & 4 deletions surrealdb/data/types/datetime.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import pytz # type: ignore

from dataclasses import dataclass
from datetime import datetime
from math import floor
from typing import Tuple

import pytz # type: ignore
from math import floor


@dataclass
class DateTimeCompact:
timestamp: int = 0 # nanoseconds

@staticmethod
def parse(seconds: int, nanoseconds: int):
def parse(seconds: int, nanoseconds: int) -> "DateTimeCompact":
return DateTimeCompact(nanoseconds + (seconds * pow(10, 9)))

def get_seconds_and_nano(self) -> Tuple[int, int]:
Expand Down
3 changes: 2 additions & 1 deletion surrealdb/data/types/duration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from dataclasses import dataclass
from math import floor
from typing import Tuple

from math import floor


@dataclass
class Duration:
Expand Down
41 changes: 41 additions & 0 deletions tests/integration/async/test_batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import List
from unittest import TestCase, main

from surrealdb import SurrealDB, RecordID
from tests.integration.connection_params import TestConnectionParams
import asyncio
import websockets


class TestBatch(TestCase):

def setUp(self) -> None:
self.params = TestConnectionParams()
self.db = SurrealDB(self.params.url)
self.queries: List[str] = []

self.db.connect()
self.db.use(self.params.namespace, self.params.database)
self.db.sign_in("root", "root")

# self.query = """
# CREATE |product:1000000| CONTENT {
# name: rand::enum('Cruiser Hoodie', 'Surreal T-Shirt'),
# colours: [rand::string(10), rand::string(10),],
# price: rand::int(20, 60),
# time: {
# created_at: rand::time(1611847404, 1706455404),
# updated_at: rand::time(1651155804, 1716906204)
# }
# };
# """
# self.db.query(query=self.query)

def tearDown(self) -> None:
pass

def test_batch(self):
print("test_batch")

if __name__ == '__main__':
main()
4 changes: 3 additions & 1 deletion tests/unit/cbor_types/test_datetime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest import TestCase
from unittest import TestCase, main

from surrealdb.data.types.datetime import DateTimeCompact
from surrealdb.data.cbor import encode, decode
Expand All @@ -21,3 +21,5 @@ def test_datetime(self):
self.assertEqual(decoded.get_date_time(), '2024-12-12T09:00:58.083988Z')


if __name__ == '__main__':
main()

0 comments on commit 782d05f

Please sign in to comment.