FAQ

What is ThingsDB and how does it differ from other programming languages?

ThingsDB is a distributed interpreter that functions as a programming language with integrated database capabilities. Unlike traditional interpreted languages such as Python, which lose variable states upon script termination, ThingsDB maintains state persistence. This means data and defined structures remain accessible and manipulable even after a query or script finishes execution. It's designed to offer a rich feature set including task scheduling, type definitions, procedures, and a pub/sub system, all while ensuring data is persistently stored in "things" (objects) within "collections" (similar to databases).

What are "things" and "properties" in ThingsDB, and how do they relate to data storage?

In ThingsDB, "things" are the fundamental objects where data is stored. Every collection has a "root" object, which is a regular "thing" and serves as the primary container for data within that collection. When you assign a value with a leading dot (e.g., .value = 'Remember me';), you are creating a "property" on the current collection's root "thing." This makes the data persistent. In contrast, assigning a value without a dot (e.g., value = "I'm a variable";) creates a "variable" which only exists within the scope of a single query and is not persistent. Each stored "thing" also receives a unique ID.

How does ThingsDB handle different data types and immutability?

ThingsDB supports various fundamental data types, including integers, floats, booleans, strings, lists, tuples, things, and sets, as well as specialized types like errors, enumerators, and flags. Integers, strings, booleans, and floating-point values are all immutable, meaning their values cannot be changed once created. Operations on these types, such as string slicing, generate new values rather than modifying the original.

What is the significance of "scopes" in ThingsDB?

Scopes in ThingsDB define distinct environments for data storage and operations. Each "collection" (which can be compared to a database in SQL) has its own unique scope. For example, the default "stuff" collection has the full scope name /collection/stuff, which can be shortened to /c/stuff or //stuff. The @ symbol can also be used to represent a scope. ThingsDB allows for multiple collections to run on a single instance, each with its isolated scope, ensuring data separation and organization.

How does ThingsDB manage relations between data and what are some common types of relations?

ThingsDB provides mechanisms to establish and manage relations between different "typed things" (custom data types). Relations are crucial for modeling complex data structures, such as a user having multiple to-do items. Common relation types include:

  • One-on-One (T? <-> T?): Where one instance of a type relates to one instance of another type, and vice-versa, with optional nillability.

  • Many-to-Many ({T} <-> {T}): Where multiple instances of one type can relate to multiple instances of another type, and vice-versa, typically involving sets.

  • One-to-Many (T? <-> {T}): Where one instance of a type can relate to multiple instances of another type (a set of things), with the reverse being a one-on-one relation, and optional nillability.

What are ThingsDB "modules" and how do they extend functionality?

ThingsDB "modules" are external components that significantly expand the core capabilities of ThingsDB. They can provide functionalities beyond standard database operations, such as sending emails, connecting to other databases, or making HTTP(S) requests. Modules can be Python-based or pre-built binary modules (often written in languages like Go). They are installed within the /thingsdb scope using the new_module() function, typically by providing a GitHub repository URL. Once installed and configured (often with authentication tokens), modules expose methods that can be called from within ThingsDB queries, allowing for interaction with external services and systems.

How does ThingsDB address query optimization and debugging?

ThingsDB offers tools and concepts to help with query optimization and debugging. The log() function, for instance, serves debugging purposes by generating warning messages to the console where the ThingsDB Node is running and emitting warning events to the client. This allows developers to track the execution flow and values during query processing. For performance optimization, ThingsDB provides functions like timeit(), which measures the execution time of code blocks, enabling developers to compare different approaches and identify more efficient solutions for their queries.

What are some of the deployment options and resources available for ThingsDB?

ThingsDB offers flexible deployment options, including:

  • From Source: Users can build ThingsDB directly from its source code, which involves cloning the GitHub repository and running a build script. This provides maximum control and customization.

  • Docker & Kubernetes: ThingsDB provides Docker images, enabling easy containerized deployment. This approach simplifies setup and ensures consistent environments. You can easily mount volumes for persistent data and module storage, and these images offer seamless integration with Kubernetes for robust orchestration and scaling of your deployments.

  • Multiple Nodes: ThingsDB supports scaling by adding multiple nodes, which can be configured to join a cluster. This is crucial for high availability and distributed data management.