Library Reference

The following is the full API reference generated from the C++ source documentation.

struct AlterStmt : public xmdb::SQL::Stmt
#include <ast.hpp>

Base class for ALTER statements.

Subclassed by xmdb::SQL::AlterUserStmt

Public Types

enum class Target : U8

Targets for ALTER statement.

Values:

enumerator USER

ALTER USER.

Public Members

Target target

The target of the ALTER operation.

class AlterUserNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing a user property alteration.

Public Types

enum class Property

Values:

enumerator PASSWORD

Change the user’s password.

Public Functions

inline explicit AlterUserNode(ok::StringView user_name, Property property, DBValue *property_value)
inline ok::StringView user_name() const
inline Property property() const
inline DBValue *property_value()

Private Members

ok::StringView m_user_name
Property m_property
DBValue *m_property_value
struct AlterUserStmt : public xmdb::SQL::AlterStmt
#include <ast.hpp>

Represents an ALTER USER statement.

Public Members

ok::String user_name

The name of the user to alter.

ok::Slice<SetClause> set_clauses

The changes to apply.

Public Static Functions

static inline AlterUserStmt *alloc(ok::Allocator *allocator, Token token, ok::StringView name, ok::Slice<SetClause> set_clauses)

Allocates a new AlterUserStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • name – The name of the user.

  • set_clauses – The changes to apply.

Returns:

Pointer to the new AlterUserStmt.

class ArgParser

Public Functions

inline ArgParser(int argc, char **argv, ok::Allocator *allocator = nullptr)
ArgParser &positional(U32 idx, const char *name)
ArgParser &string(const char *name, const char **dest, const char *description, const char *default_value = nullptr)
ArgParser &integer(const char *name, S64 *dest, const char *description, ok::Optional<S64> default_value = {})
ArgParser &boolean(const char *name, bool *dest, const char *description)
bool parse()
ok::Slice<const char*> positionals()
ok::StringView error_message()
void help()
void dealloc()
inline ~ArgParser()

Private Functions

inline void flag(const char *name, Flag type, void *dest, const char *description, const void *default_value)

Private Members

int m_argc
char **m_argv
ok::Allocator *m_allocator
ok::List<FlagSpec> m_flag_specs
ok::List<PositionalSpec> m_positional_specs
ok::List<const char*> m_positionals
ok::String m_error_message
bool m_failed
class AtomicNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing a collection of operations that must be performed atomically.

Public Functions

inline explicit AtomicNode(ok::Allocator *allocator)
inline void add(Node *node)
inline ok::Slice<Node*> nodes()

Private Members

ok::List<Node*> m_nodes
struct BinaryOpExpr : public xmdb::SQL::Expr
#include <ast.hpp>

Represents a binary operation expression.

Public Types

enum class Kind : U8

Kinds of binary operations.

Values:

enumerator EQ

Equality.

enumerator GT

Greater than.

enumerator LT

Less than.

Public Members

Kind kind

The kind of binary operation.

Expr *lhs

Left-hand side operand.

Expr *rhs

Right-hand side operand.

Public Static Functions

static inline BinaryOpExpr *alloc(ok::Allocator *allocator, Token token, Kind kind, Expr *lhs, Expr *rhs)

Allocates a new BinaryOpExpr.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • kind – The kind of binary operation.

  • lhs – Left-hand side operand.

  • rhs – Right-hand side operand.

Returns:

Pointer to the new BinaryOpExpr.

struct BTreeIndex
#include <BTreeIndex.hpp>

A B-Tree index for efficient key-value lookups and storage.

Public Functions

void insert(U64 key)

Inserts a key into the index.

Parameters:

key – The key to insert.

bool contains(U64 key)

Checks if the index contains a specific key.

Parameters:

key – The key to look for.

Returns:

true if found, false otherwise.

bool remove(U64 key)

Removes a key from the index.

Parameters:

key – The key to remove.

Returns:

true if successful, false otherwise.

bool first_constructed()

Checks if the index was just first_constructed.

Returns:

true if it was first_constructed, false otherwise.

UZ order()

Gets the order of the B-Tree.

Returns:

The order.

U64 height()

Gets the height of the B-Tree.

Returns:

The height.

U64 node_count()

Gets the total number of nodes in the B-Tree.

Returns:

The node count.

U64 total_kv_count()

Gets the total number of key-value pairs in the index.

Returns:

The KV count.

bool reset()

Resets the index, clearing all data.

Returns:

true if successful, false otherwise.

Public Members

void *pImpl

Pointer to the internal implementation.

Public Static Functions

static ok::Optional<ok::File::OpenError> create(ok::Allocator *allocator, ok::StringView state_filename, BTreeIndex *index)

Creates a new BTreeIndex from a state file.

Parameters:
  • allocator – The allocator to use.

  • state_filename – The path to the state file.

  • index – Pointer to store the resulting index.

Returns:

An optional open error if the operation failed.

static BTreeIndex create(ok::Allocator *allocator, ok::File state_file)

Creates a BTreeIndex from an already open state file.

Parameters:
  • allocator – The allocator to use.

  • state_file – The open state file.

Returns:

The resulting BTreeIndex.

struct BTreeState

Public Functions

inline ok::Optional<ok::String> reset()
inline void free() const
inline S64 node_search(Node *node, U64 key, Node **out_node)
inline S64 search(U64 key, Node **out_node)
inline bool remove_node(Node *node, U64 key)
inline bool remove(U64 key)
inline Node *load_node_from_disk(Node *parent, U64 child_index)
inline void save_node_to_disk(Node *node)
inline void save_header_to_disk()
inline void split_child(Node *parent, Node *full_child, U64 full_child_index)
inline void insert(U64 key)
inline void insert_non_full(Node *node, U64 key)
inline Node *alloc_node_without_backing_disk_buffer()
inline Node *alloc_node_with_backing_disk_buffer()

Public Members

ok::Allocator *allocator
ok::File state_file
DiskHeader *header
Node *root
ok::Slice<U8> write_buffer
BTreeStateFlags flags
U64 current_node_id

Public Static Functions

static inline ok::Optional<ok::String> create(ok::Allocator *allocator, ok::File state_file, BTreeState **out_state)
struct CallExpr : public xmdb::SQL::Expr
#include <ast.hpp>

Represents a function call expression.

Public Members

Expr *fn

The function being called.

ok::Slice<Expr*> args

The arguments to the function call.

Public Static Functions

static inline CallExpr *alloc(ok::Allocator *allocator, Token token, Expr *fn, ok::Slice<Expr*> args)

Allocates a new CallExpr.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • fn – The function expression.

  • args – The arguments to the function call.

Returns:

Pointer to the new CallExpr.

class CallNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing a function call.

Public Functions

inline CallNode(Allocator *allocator, StringView fn_name, Slice<DBValue*> args)
inline Slice<DBValue*> args() const
inline DelayedDBValue *return_value() const
inline StringView fn_name() const

Private Members

StringView m_fn_name
Slice<DBValue*> m_args
DelayedDBValue *m_return_value
struct CatalogDBEntry

Public Members

FixedString name
U64 user_count
U64 table_count
struct CatalogHeader

Public Members

U64 magic
U64 version
U64 db_count
struct CatalogTableEntry

Public Members

FixedString name
DBTable::Flags flags
U64 column_count
struct CatalogUserEntry

Public Members

FixedString name
U8 sha256_password_digest[SHA256Digest::SIZE]
U8 perm
struct ChunkIndices
#include <image.hpp>

Stores indices of image chunks.

Public Members

U8 count

The number of chunk indices.

U32 items[MAX_DISK_IMAGE_CHUNKS_COUNT]

The chunk indices.

struct ColumnAttribute
#include <DBTable.hpp>

Attributes of a column.

Public Types

Values:

enumerator F_IMAGE

The column contains image data.

using Flags = U8

Public Members

Flags flags

The attribute flags.

ImageColumnState image_state

State for image columns.

union xmdb::ColumnAttribute u
class ColumnDBValue : public xmdb::DBValue
#include <DBValue.hpp>

A DBValue representing a column in a specific table.

Public Functions

inline ColumnDBValue(SQL::Type type, ColumnLayout layout, DBTable *table)

Constructs a new ColumnDBValue.

Parameters:
  • type – The SQL type of the column.

  • layout – The layout of the column.

  • table – The table the column belongs to.

inline DBTable *table()

Gets the table this column value belongs to.

Returns:

Pointer to the table.

inline ColumnLayout layout()

Gets the layout of the column.

Returns:

The column layout.

Private Members

ColumnLayout m_layout
DBTable *m_table
class ColumnDescriptor
#include <TableStream.hpp>

Describes a column in a row.

Public Functions

explicit ColumnDescriptor(RowDescriptor &row_desc, U64 index)

Constructs a new ColumnDescriptor.

Parameters:
  • row_desc – Reference to the row descriptor this column belongs to.

  • index – The index of the column.

inline U64 index() const

Gets the column index.

Returns:

The index.

Private Members

RowDescriptor &m_row_descriptor
U64 m_index
struct ColumnLayout
#include <ColumnLayout.hpp>

Layout information for a single column in a table record.

Public Members

U64 index

The index of the column.

U64 offset

The byte offset of the column within the record.

U64 size

The size of the column in bytes.

struct ColumnStream

Public Members

DBTable *table
UZ column_index
UZ current_record
U8 *buffer
class CompareDBValue : public xmdb::DBValue
#include <DBValue.hpp>

A DBValue representing a comparison between two other values.

Public Functions

inline CompareDBValue(DBValue *lhs, DBValue *rhs)

Constructs a comparison value.

Parameters:
  • lhs – The left-hand side value.

  • rhs – The right-hand side value.

inline DBValue *lhs()

Gets the left-hand side of the comparison.

Returns:

Pointer to the LHS value.

inline DBValue *rhs()

Gets the right-hand side of the comparison.

Returns:

Pointer to the RHS value.

Private Members

DBValue *m_lhs
DBValue *m_rhs
struct CompiledQuery
#include <ir.hpp>

Represents a compiled SQL query in IR.

Public Members

Slice<IRInstruction> instructions

The instructions.

Slice<Token> tokens

The tokens.

Slice<String> strings

The strings.

Slice<S64> integers

The integers.

Slice<TableSchema*> schemas

The schemas.

struct ComputationStream

Public Members

Computation comp
void *arg
class ConcatDBValue : public xmdb::PairDBValue
#include <DBValue.hpp>

A DBValue representing the concatenation of two values.

Public Functions

inline ConcatDBValue(DBValue *lhs, DBValue *rhs)

Constructs a concatenation value.

Parameters:
  • lhs – The first value to concatenate.

  • rhs – The second value to concatenate.

struct Config

Public Members

Protocol protocol
U16 port

Public Static Functions

static Config parse(int argc, char **argv)
struct ConnectionData

Public Members

ConnectionData *next
xmdb::DBConnection *connection
ok::ArenaAllocator temp_arena
xmdb::DBUser *user
Timestamp last_use_time
class ConstDBValue : public xmdb::DBValue
#include <DBValue.hpp>

A DBValue representing a constant (literal) value.

Public Types

enum class ConstKind

The kind of constant value.

Values:

enumerator INT

Integer constant.

enumerator STRING

String constant.

enumerator BOOL

Boolean constant.

Public Functions

inline explicit ConstDBValue(S64 i)

Constructs a constant integer value.

Parameters:

i – The integer value.

inline explicit ConstDBValue(ok::String *s)

Constructs a constant string value.

Parameters:

s – Pointer to the string value.

inline explicit ConstDBValue(bool b)

Constructs a constant boolean value.

Parameters:

b – The boolean value.

inline ConstKind kind() const

Gets the constant kind.

Returns:

The constant kind.

inline S64 as_int() const

Retrieves the value as an integer.

Returns:

The integer value.

inline bool as_bool() const

Retrieves the value as a boolean.

Returns:

The boolean value.

inline ok::String *as_string()

Retrieves the value as a string.

Returns:

Pointer to the string value.

Private Functions

inline explicit ConstDBValue(SQL::Type type, ConstKind kind, void *data)

Private Members

ConstKind m_const_kind
void *m_data
struct CreateDatabaseStmt : public xmdb::SQL::CreateStmt
#include <ast.hpp>

Represents a CREATE DATABASE statement.

Public Static Functions

static inline CreateDatabaseStmt *alloc(ok::Allocator *allocator, Token token, ok::String name)

Allocates a new CreateDatabaseStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • name – The name of the database.

Returns:

Pointer to the new CreateDatabaseStmt.

struct CreateStmt : public xmdb::SQL::Stmt
#include <ast.hpp>

Base class for CREATE statements.

Subclassed by xmdb::SQL::CreateDatabaseStmt, xmdb::SQL::CreateTableStmt, xmdb::SQL::CreateUserStmt

Public Types

enum class Target : U8

Targets for CREATE statement.

Values:

enumerator DATABASE

CREATE DATABASE.

enumerator TABLE

CREATE TABLE.

enumerator USER

CREATE USER.

Public Members

Target target

The target of the CREATE operation.

ok::String name

The name of the target.

struct CreateTableStmt : public xmdb::SQL::CreateStmt
#include <ast.hpp>

Represents a CREATE TABLE statement.

Public Members

ok::Slice<ok::String> column_names

The names of the columns.

ok::Slice<ok::String> column_types

The types of the columns.

Public Static Functions

static inline CreateTableStmt *alloc(ok::Allocator *allocator, Token token, ok::String name, ok::Slice<ok::String> column_names, ok::Slice<ok::String> column_types)

Allocates a new CreateTableStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • name – The name of the table.

  • column_names – The names of the columns.

  • column_types – The types of the columns.

Returns:

Pointer to the new CreateTableStmt.

struct CreateUserStmt : public xmdb::SQL::CreateStmt
#include <ast.hpp>

Represents a CREATE USER statement.

Public Static Functions

static inline CreateUserStmt *alloc(ok::Allocator *allocator, Token token, ok::String name)

Allocates a new CreateUserStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • name – The name of the user.

Returns:

Pointer to the new CreateUserStmt.

struct DBConnection
#include <DBConnection.hpp>

Represents an active connection to a database.

Public Functions

explicit DBConnection(DBPool *pool, DBDescriptor *db, DBUser *user)

Constructs a new DBConnection.

Parameters:
  • pool – The database pool this connection belongs to.

  • db – The database descriptor for this connection.

  • user – The user associated with this connection.

void execute(SQL::TypedCompiledQuery *query, QueryResults *results)

Executes a compiled SQL query.

Parameters:
  • query – The compiled query to execute.

  • results – Pointer to a structure where results will be stored.

void close()

Closes the connection and releases resources.

Public Members

DBPool *db_pool

Pointer to the database pool.

DBUser *user

Pointer to the associated user.

DBDescriptor *db

Pointer to the database descriptor.

SQL::IrContext ir_ctx

The intermediate representation context for execution of queries.

struct DBDescriptor
#include <DBDescriptor.hpp>

Describes a database and manages its tables and users.

Public Functions

inline void add_user(DBUser *user)

Adds a user to the database.

Parameters:

user – The user to add.

inline Optional<DBUser*> find_user(StringView name)

Finds a user by name.

Parameters:

name – The name of the user to find.

Returns:

An optional containing the user if found, or empty otherwise.

DBTable *create_new_table(ok::Allocator *allocator, ok::StringView name, DBTable::Flags flags, UZ column_count, ok::Slice<ok::StringView> column_names, ok::Slice<SQL::ColumnType> column_types)

Creates a new table in the database.

Parameters:
  • allocator – The allocator to use for the table.

  • name – The name of the table.

  • flags – The table flags (e.g., storage type).

  • column_count – The number of columns in the table.

  • column_names – The names of the columns.

  • column_types – The types of the columns.

Returns:

A pointer to the newly created table.

Result<DBTable*, ok::String> load_existing_table(ok::Allocator *allocator, ok::StringView name, DBTable::Flags flags, UZ column_count, ok::Slice<ok::StringView> column_names, ok::Slice<SQL::ColumnType> column_types)

Loads an existing table from disk.

Parameters:
  • allocator – The allocator to use for the table.

  • name – The name of the table.

  • flags – The table flags (e.g., storage type).

  • column_count – The number of columns in the table.

  • column_names – The names of the columns.

  • column_types – The types of the columns.

Returns:

A result with an allocated table on success, an error string otherwise.

Public Members

DBDescriptor *next

Pointer to the next database descriptor in a list.

ok::StringView name

The name of the database.

DBUser *users

Pointer to the head of the users list.

ok::List<DBTable*> tables

List of tables in the database.

Public Static Functions

static DBDescriptor *alloc(ok::Allocator *allocator, ok::StringView name)

Allocates a new DBDescriptor.

Parameters:
  • allocator – The allocator to use for the descriptor.

  • name – The name of the database.

Returns:

A pointer to the newly allocated DBDescriptor.

struct DBPool
#include <DBPool.hpp>

Manages a pool of databases and execution contexts.

Public Types

Values:

enumerator F_EPHEMERAL

No catalog data will be loaded or stored.

using Flags = U16

Public Functions

DBPool(ok::Allocator *allocator, Flags flags = 0)

Constructs a new DBPool.

Parameters:
  • allocator – The allocator to use for pool resources.

  • flags – Flags for this pool.

DBDescriptor *get_db(StringView name)

Retrieves a database descriptor by name.

Parameters:

name – The name of the database.

Returns:

A pointer to the database descriptor, or nullptr if not found.

DBDescriptor *create_db(StringView name)

Creates a new database with the given name.

Parameters:

name – The name of the new database.

Returns:

A pointer to the newly created database descriptor.

QueryExecutionContext *rent_empty_execution_context(DBDescriptor *db, DBUser *user)

Rents an empty execution context for a specific database and user.

Parameters:
  • db – The database to use for execution.

  • user – The user associated with the execution.

Returns:

A pointer to the rented execution context.

void return_execution_context(QueryExecutionContext *context)

Returns an execution context to the pool.

Parameters:

context – The execution context to return.

Result<UZ, ok::String> sync_to_disk()

Tries to sync this pool’s catalog to disk.

Returns:

The number of bytes written on success, error string otherwise.

inline bool ephemeral() const

Returns whether this DBPool is ephemeral.

Returns:

true if the F_EPHEMERAL flag is set, false otherwise

Public Members

ok::Allocator *allocator

The allocator for the pool.

Flags flags

Behavior flags.

QueryExecutionContext *execution_contexts

List of available execution contexts.

DBDescriptor *db_descriptors

List of database descriptors.

ok::StringView catalog_file_name

File name for the pool’s catalog.

struct DBRecord
#include <DBRecord.hpp>

Represents a single record (row) in a database table.

Public Members

U8 *buffer

The buffer containing the record data.

UZ buffer_size

The size of the buffer.

U64 primary_key_value

The value of the primary key for this record.

struct DBSchema
#include <ir.hpp>

Represents a database schema in the IR.

Public Functions

inline TableSchema *alloc_table_schema(Optional<String> name, bool typed)

Allocates a new TableSchema within this DBSchema.

Parameters:
  • name – The name of the table.

  • typed – Whether the schema is typed.

Returns:

Pointer to the new TableSchema.

Public Members

U32 table_schema_count

Number of table schemas.

Allocator *allocator

The allocator.

TableSchema *table_schemas

Pointer to the array of table schemas.

String name

Name of the database.

Table<String, U32> table_schemas_index

Mapping of names to indices.

Public Static Functions

static inline DBSchema alloc(Allocator *allocator, StringView name)

Allocates a new DBSchema.

Parameters:
  • allocator – The allocator to use.

  • name – The name of the database.

Returns:

The new DBSchema.

static inline DBSchema alloc_default(Allocator *allocator)

Allocates the default DBSchema.

Parameters:

allocator – The allocator to use.

Returns:

The default DBSchema.

struct DBState
#include <state.hpp>

Represents the persistent state of a database table.

Public Members

DBStateHeader header

The state header.

ok::File file

The backing file for the state.

struct DBStateHeader
#include <state.hpp>

Header for a table state file.

Public Members

U64 magic

Magic number identifying the file type.

U64 record_count

Total number of records in the table.

class DBTable
#include <DBTable.hpp>

Represents a database table, managing its metadata and data.

Public Types

Table flags indicating its nature and storage.

Values:

enumerator F_ANON

Anonymous table.

enumerator F_PERSIST

Persistent table (stored on disk).

enumerator F_PROXY

Proxy table (values are held externally).

enumerator F_EPHEMERAL

Ephemeral table (temporary).

using Flags = U16

Public Functions

DBTable(ok::Allocator *allocator, Flags flags, ok::StringView name, UZ column_count, ok::StringView *column_names, SQL::ColumnType *column_types)

Constructs a new DBTable.

Parameters:
  • allocator – The allocator to use.

  • flags – The table flags.

  • name – The name of the table.

  • column_count – The number of columns.

  • column_names – The names of the columns.

  • column_types – The types of the columns.

DBTable(ok::Allocator *allocator, Flags flags, ok::StringView name, UZ column_count, ok::StringView *column_names, SQL::ColumnType *column_types, ColumnAttribute *column_attributes)

Constructs a new DBTable.

Parameters:
  • allocator – The allocator to use.

  • flags – The table flags.

  • name – The name of the table.

  • column_count – The number of columns.

  • column_names – The names of the columns.

  • column_types – The types of the columns.

  • column_attributes – The attributes of the columns.

inline Flags flags() const

Gets the table flags.

Returns:

The flags.

inline ok::StringView name() const

Gets the table name.

Returns:

The name.

inline UZ columns_count() const

Gets the number of columns in the table.

Returns:

The column count.

inline ok::Slice<ok::StringView> columns_names()

Gets the names of the columns.

Returns:

A slice of column names.

inline ok::Slice<SQL::ColumnType> columns_types()

Gets the types of the columns.

Returns:

A slice of column types.

inline TableLayout layout() const

Gets the table layout.

Returns:

The layout.

inline UZ rows_count()

Gets the total number of rows in the table.

Returns:

The row count.

inline void set_proxy_rows_count(UZ x)

Sets the row count for a proxy table.

Parameters:

x – The row count.

inline void set_proxy_column_values(ok::Slice<DBValue*> values)

Sets the values for a proxy table’s columns.

Parameters:

values – A slice of pointers to DBValue.

inline ok::Slice<DBValue*> proxy_column_values()

Gets the column values for a proxy table.

Returns:

A slice of pointers to DBValue.

inline BTreeIndex *index()

Gets the B-Tree index for a persistent table.

Returns:

Pointer to the index.

inline void set_index(BTreeIndex index)

Sets the B-Tree index for the table.

Parameters:

index – The index to set.

inline DBState *state()

Gets the persistence state for the table.

Returns:

Pointer to the state.

inline void set_state(DBState state)

Sets the persistence state for the table.

Parameters:

state – The state to set.

inline ok::Slice<ColumnAttribute> column_attributes()

Gets the attributes for each column.

Returns:

A slice of column attributes.

Private Members

ok::StringView m_name
U16 m_flags
UZ m_columns_count
ok::StringView *m_columns_names
SQL::ColumnType *m_columns_types
TableLayout m_layout
DBValue **m_proxy_columns_values
ColumnAttribute *m_column_attributes
UZ m_proxy_rows_count
BTreeIndex m_index
DBState m_state
class DBTableOutlet
#include <DBTable.hpp>

Acts as an outlet for a DBTable, providing access to its columns as streams.

Public Functions

inline explicit DBTableOutlet(DBTable *table)

Constructs a new DBTableOutlet.

Parameters:

table – The table to act as an outlet for.

inline DBTableStream column_stream(ok::Allocator *allocator, UZ i)

Creates a stream for a specific column in the table.

Parameters:
  • allocator – The allocator to use for the stream.

  • i – The column index.

Returns:

The resulting DBTableStream.

Private Members

DBTable *m_table
class DBTableStream
#include <DBTable.hpp>

Provides a stream-like interface for pulling values out of different sources i.e. a DBTable or DBValue.

Public Types

enum class Type

The type of data source for the stream.

Values:

enumerator CONSTANT

Stream from a constant value.

enumerator COLUMN

Stream from a table column.

enumerator COMPUTE

Stream from a computation function.

using Computation = ok::Optional<Value> (*)(void*)

Public Functions

inline explicit DBTableStream(ok::Allocator *allocator, ConstDBValue constant)

Constructs a DBTableStream from a constant value.

Parameters:
  • allocator – The allocator to use.

  • constant – The constant value.

inline DBTableStream(ok::Allocator *allocator, Computation comp, void *arg)

Constructs a DBTableStream from a computation function.

Parameters:
  • allocator – The allocator to use.

  • comp – The computation function.

  • arg – The argument to pass to the computation function.

inline DBTableStream(ok::Allocator *allocator, DBTable *table, UZ column_index)

Constructs a DBTableStream from a table column.

Parameters:
  • allocator – The allocator to use.

  • table – The table to stream from.

  • column_index – The index of the column to stream.

ok::Optional<Value> next()

Retrieves the next value from the stream.

Returns:

An optional containing the next value, or empty if the stream has ended.

Public Members

ConstDBValue constant
ComputationStream compute
ColumnStream column

Public Static Functions

static DBTableStream from_value(ok::Allocator *allocator, DBValue *value)

Creates a DBTableStream from a DBValue.

Parameters:
  • allocator – The allocator to use.

  • value – The value to stream from.

Returns:

The resulting stream.

Private Members

ok::Allocator *m_allocator
Type m_type
union xmdb::DBTableStream m_u
struct DBUser
#include <DBUser.hpp>

Represents a database user with specific permissions.

Public Functions

DBUser(ok::StringView name, ok::StringView password, U8 perm)

Constructs a new DBUser.

Parameters:
  • name – The user’s name.

  • password – The user’s password.

  • perm – The user’s permissions.

Public Members

DBUser *next

Pointer to the next user in a list.

ok::StringView name

The user’s name.

SHA256Digest sha256_password_digest

The SHA-256 digest of the user’s password.

U8 perm

The user’s permissions bitfield.

Public Static Functions

static inline DBUser admin()

Creates a default admin user.

Returns:

A default admin user.

class DBValue
#include <DBValue.hpp>

Abstract base class for database values used in query planning and execution.

Subclassed by xmdb::ColumnDBValue, xmdb::CompareDBValue, xmdb::ConstDBValue, xmdb::DelayedDBValue, xmdb::ImageDataDBValue, xmdb::NoneDBValue, xmdb::PairDBValue

Public Types

enum class Kind

The kind of database value.

Values:

enumerator COLUMN

Value from a table column.

enumerator COMPARE

Result of a comparison.

enumerator CONSTANT

A constant value.

enumerator NONE

Represents no value or null.

enumerator CONCAT

Result of a concatenation.

enumerator IMAGE_DATA

Raw image data.

enumerator DELAYED

A value that will be provided later.

Public Functions

DBValue() = delete
inline SQL::Type type() const

Gets the SQL type of the value.

Returns:

The SQL type.

inline Kind kind() const

Gets the kind of the value.

Returns:

The kind.

inline bool is_compatible_with(const DBValue *other) const

Checks if this value is type-compatible with another value. NONE values are compatible with any value.

Parameters:

other – The other value to check against.

Returns:

true if compatible, false otherwise.

Public Static Functions

static inline DBValue *null()

Statically allocates a null value.

Returns:

The null value.

Protected Functions

inline DBValue(SQL::Type type, Kind kind)

Protected Attributes

SQL::Type m_type
Kind m_kind
class DelayedDBValue : public xmdb::DBValue
#include <DBValue.hpp>

A DBValue whose underlying value is determined later during execution.

Public Functions

inline explicit DelayedDBValue()

Constructs a new DelayedDBValue.

inline void set(DBValue *value)

Sets the actual value.

Parameters:

value – Pointer to the DBValue to set.

inline ok::Optional<DBValue*> value()

Gets the actual value if it has been set.

Returns:

An optional containing the value.

Private Members

ok::Optional<DBValue*> m_value
struct DeleteStmt : public xmdb::SQL::Stmt
#include <ast.hpp>

Represents a DELETE statement.

Public Members

Expr *table

The table to delete from.

ok::Optional<Expr*> filter

The WHERE clause filter.

Public Static Functions

static inline DeleteStmt *alloc(ok::Allocator *allocator, Token token, Expr *table, ok::Optional<Expr*> filter)

Allocates a new DeleteStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • table – The table expression.

  • filter – The filter expression.

Returns:

Pointer to the new DeleteStmt.

class DeleteTableNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing a table deletion.

Public Functions

inline explicit DeleteTableNode(DBTable *table)
inline DBTable *table() const

Private Members

DBTable *m_table
struct DiskHeader

Public Members

U64 magic
U16 version
U64 index_nodes_count
U64 kv_count
U64 payload_length
U64 height

Public Static Functions

static inline DiskHeader *alloc(ok::Allocator *allocator)
struct DiskImageChunk
#include <image.hpp>

Represents a chunk of image data as stored on disk.

Public Members

U64 x

X-coordinate of the chunk.

U64 y

Y-coordinate of the chunk.

U64 width

Width of the chunk.

U64 height

Height of the chunk.

U8 pixel_data[]

Variable-length array of pixel data.

struct DiskNode

Public Members

bool is_leaf
bool is_root
U64 keys_count
U64 keys[BTREE_MAX_KEYS]
U64 children[BTREE_MAX_CHILDREN]
class DiskStore : public xmdb::Store
#include <TableStream.hpp>

Disk-based storage backend.

Public Functions

inline DiskStore()

Constructs a new DiskStore.

struct DropStmt : public xmdb::SQL::Stmt
#include <ast.hpp>

Represents a DROP statement.

Public Types

enum class Target : U8

Targets for DROP statement.

Values:

enumerator TABLE

DROP TABLE.

enumerator DATABASE

DROP DATABASE.

Public Members

Target target

The target of the DROP operation.

ok::String name

The name of the target.

Public Static Functions

static inline DropStmt *alloc(ok::Allocator *allocator, Token token, Target target, ok::String name)

Allocates a new DropStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • target – The target of the DROP operation.

  • name – The name of the target.

Returns:

Pointer to the new DropStmt.

class EmitQueryNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing the emission of a query’s result set.

Public Functions

inline EmitQueryNode(Allocator *allocator, Slice<DBTable*> queried_tables, Slice<StringView> column_names, Slice<DBValue*> column_values, Slice<SQL::ColumnType> column_types)
inline DBTable *table() const
inline Slice<DBTable*> queried_tables() const
inline Slice<DBValue*> column_values() const

Private Members

Slice<DBTable*> m_queried_tables
Slice<DBValue*> m_column_values
DBTable *m_emitted_table
struct ErrorWithSourceLocation
#include <util.hpp>

Represents an error message paired with its source location.

Public Members

ok::String message

The error message.

SourceLocation location

The location in the source code where the error occurred.

struct Expr
#include <ast.hpp>

Base class for all SQL expressions in the AST.

Subclassed by xmdb::SQL::BinaryOpExpr, xmdb::SQL::CallExpr, xmdb::SQL::IdentifierExpr, xmdb::SQL::IntegerExpr, xmdb::SQL::SelectExpr, xmdb::SQL::StarExpr, xmdb::SQL::StringExpr

Public Types

enum Type

Types of SQL expressions.

Values:

enumerator IDENT

Identifier.

enumerator INTEGER_LIT

Integer literal.

enumerator STRING_LIT

String literal.

enumerator TRUE_LIT

Boolean TRUE literal.

enumerator FALSE_LIT

Boolean FALSE literal.

enumerator NULL_LIT

NULL literal.

enumerator BINARY_OP

Binary operation.

enumerator SELECT

SELECT expression.

enumerator STAR

Star (‘*’) expression.

enumerator CALL

Function call expression.

Public Functions

U64 ok_hash_value() const

Computes a hash value for the expression.

Returns:

The hash value.

bool operator==(const Expr &other) const
ok::String to_string(ok::Allocator *allocator) const

Converts the expression to a string representation.

Parameters:

allocator – The allocator to use for the string.

Returns:

The string representation.

Public Members

Type type

The type of the expression.

Token token

The primary token of the expression.

Public Static Functions

static inline Expr *alloc_true(ok::Allocator *allocator, Token token)

Allocates a TRUE literal expression.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

Returns:

Pointer to the new Expr.

static inline Expr *alloc_false(ok::Allocator *allocator, Token token)

Allocates a FALSE literal expression.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

Returns:

Pointer to the new Expr.

static inline Expr *alloc_null(ok::Allocator *allocator, Token token)

Allocates a NULL literal expression.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

Returns:

Pointer to the new Expr.

struct ExprStmt : public xmdb::SQL::Stmt
#include <ast.hpp>

Represents an expression statement.

Public Members

Expr *expr

The expression.

Public Static Functions

static inline ExprStmt *alloc(ok::Allocator *allocator, Token token, Expr *expr)

Allocates a new ExprStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • expr – The expression.

Returns:

Pointer to the new ExprStmt.

struct FileLogger : public xmdb::Logger
#include <Logger.hpp>

A logger that outputs to a FILE* handle.

Public Functions

inline FileLogger(LogLevel lvl, FILE *file)

Constructs a new FileLogger.

Parameters:
  • lvl – The minimum log level.

  • file – The file to log to.

inline virtual void set_log_level(LogLevel lvl) override

Sets the minimum log level.

Parameters:

lvl – The log level to set.

virtual void log(LogLevel level, const char *fmt, va_list args) override

Logs a message to the file.

Parameters:
  • level – The log level.

  • fmt – The format string.

  • args – The variable arguments.

Public Members

LogLevel log_level

The current minimum log level.

FILE *file

The file pointer.

struct FixedString
#include <FixedString.hpp>

A string with a fixed maximum size, suitable for storage in table records.

Public Functions

inline ok::StringView view() const

Gets a view of the string.

Returns:

An ok::StringView representing the string content.

Public Members

U8 count

Current number of characters in the string.

U8 items[DATA_SIZE]

The character data.

Public Static Attributes

static constexpr UZ DATA_SIZE = 63

Maximum number of characters.

static constexpr UZ PREFIX_SIZE = 1

Size of the length prefix.

struct FlagSpec

Public Members

const char *name
const char *description
Flag type
void *dest
const void *default_value
struct FunctionSignature
#include <type_check.hpp>

Signature of a SQL function.

Public Members

Type return_type

The type of the value returned by the function.

Slice<Type> parameter_types

The types of the function parameters.

struct HttpServerState
struct IdentifierExpr : public xmdb::SQL::Expr
#include <ast.hpp>

Represents an identifier expression (e.g. column name).

Public Members

ok::String value

The identifier value.

Public Static Functions

static inline IdentifierExpr *alloc(ok::Allocator *allocator, Token token, ok::StringView value)

Allocates a new IdentifierExpr.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • value – The identifier string.

Returns:

Pointer to the new IdentifierExpr.

struct ImageChunk
#include <image.hpp>

Represents a chunk of image data in memory.

Public Members

U32 x

X-coordinate of the chunk’s top-left corner.

U32 y

Y-coordinate of the chunk’s top-left corner.

U32 width

Width of the chunk in pixels.

U32 height

Height of the chunk in pixels.

ok::Slice<U8> data

The raw pixel data.

PixelFormat pixel_format

The format of the pixel data.

struct ImageColumnState
#include <state.hpp>

Represents the persistent state of an image column.

Public Members

ImageColumnStateHeader header

The state header.

ok::File file

The backing file.

struct ImageColumnStateHeader
#include <state.hpp>

Header for an image column state file.

Public Members

U64 magic

Magic number.

U64 chunks_count

Number of image chunks stored.

class ImageDataDBValue : public xmdb::DBValue
#include <DBValue.hpp>

A DBValue representing raw image data.

Public Functions

inline ImageDataDBValue(U32 width, U32 height, ok::Slice<U8> data, PixelFormat format)

Constructs an image data value.

Parameters:
  • width – The width of the image.

  • height – The height of the image.

  • data – The raw pixel data.

  • format – The pixel format.

inline U32 width()

Gets the width of the image.

Returns:

The width.

inline U32 height()

Gets the height of the image.

Returns:

The height.

inline ok::Slice<U8> data()

Gets the raw pixel data.

Returns:

A slice of the pixel data.

inline PixelFormat format()

Gets the pixel format.

Returns:

The format.

Private Members

U32 m_width
U32 m_height
ok::Slice<U8> m_data
PixelFormat m_format
class InsertNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing an insertion of rows into a table.

Public Types

using ValuesSlice = Slice<ok::Pair<StringView, DBValue*>>

Public Functions

inline InsertNode(DBTable *table, Slice<StringView> column_names, Slice<DBValue*> column_values, UZ rows_count)
inline DBTable *table() const
inline Slice<StringView> column_names() const
inline Slice<DBValue*> column_values() const
inline UZ rows_count() const

Private Members

DBTable *m_table
Slice<StringView> m_column_names
Slice<DBValue*> m_column_values
UZ m_rows_count
struct InsertStmt : public xmdb::SQL::Stmt
#include <ast.hpp>

Represents an INSERT statement.

Public Members

ok::String table_name

The name of the table to insert into.

ok::Slice<ok::String> columns

The columns to insert values for.

ok::Slice<Expr*> values

The values to insert.

ok::Slice<uint32_t> values_counts

The number of values in each row.

Public Static Functions

static inline InsertStmt *alloc(ok::Allocator *allocator, Token token, ok::StringView table_name, ok::Slice<ok::String> columns, ok::Slice<Expr*> values, ok::Slice<uint32_t> values_counts)

Allocates a new InsertStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • table_name – The name of the table.

  • columns – The names of the columns.

  • values – The values to insert.

  • values_counts – The number of values per row.

Returns:

Pointer to the new InsertStmt.

struct IntegerExpr : public xmdb::SQL::Expr
#include <ast.hpp>

Represents an integer literal expression.

Public Members

int64_t value

The integer value.

Public Static Functions

static inline IntegerExpr *alloc(ok::Allocator *allocator, Token token, int64_t value)

Allocates a new IntegerExpr.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • value – The integer value.

Returns:

Pointer to the new IntegerExpr.

struct IrContext
#include <ir.hpp>

Context for compiling AST to IR.

Public Types

enum Namespace

Namespace types.

Values:

enumerator NS_GLOBAL
enumerator NS_TABLE

Public Functions

IrContext() = default
inline explicit IrContext(Allocator *allocator, StringView source)

Constructs a new IrContext.

Parameters:
  • allocator – The allocator to use.

  • source – The original SQL source.

inline DBSchema *active_db_schema()

Gets the active database schema.

Returns:

Pointer to the active DBSchema.

inline Optional<TableSchema*> get_table_schema(U8 db_schema_id, StringView table_name)

Retrieves a TableSchema by its name within a database.

Parameters:
  • db_schema_id – The ID of the database schema.

  • table_name – The name of the table.

Returns:

Optional pointer to the TableSchema.

inline Optional<TableSchema*> get_table_schema_by_id(U32 id)

Retrieves a TableSchema by instruction ID.

Parameters:

id – The instruction ID.

Returns:

Optional pointer to the TableSchema.

inline TableSchema *alloc_table_schema(U8 db_schema_id, Optional<String> table_name, bool typed)

Allocates a new TableSchema.

Parameters:
  • db_schema_id – The database schema ID.

  • table_name – The name of the table.

  • typed – Whether the schema is typed.

Returns:

Pointer to the new TableSchema.

inline U32 current_table_id() const

Gets the ID of the current table.

Returns:

The table ID.

inline Namespace current_namespace() const

Gets the current namespace.

Returns:

The namespace.

inline void push_namespace(Namespace ns)

Pushes a new namespace.

Parameters:

ns – The namespace to push.

inline void push_table(U32 table_id)

Pushes a table namespace.

Parameters:

table_id – The ID of the table.

inline void pop_namespace()

Pops the current namespace.

inline void error_on(Token token, String message)

Records an error at a token location.

Parameters:
  • token – The token where the error occurred.

  • message – The error message.

Public Members

Allocator *allocator

The allocator.

StringView source

The original source.

List<DBSchema> database_schemas

List of database schemas.

List<U32> table_stack

Stack of table IDs.

List<Namespace> namespace_stack

Stack of namespaces.

IREmitter ir_emitter

The IR emitter.

U32 active_db_id = 0

The active database ID.

Optional<ErrorWithSourceLocation> error = {}

Error information.

template<typename T>
struct IRContractAdder
template<>
struct IRContractAdder<S64>

Public Static Functions

static inline U32 add(IREmitter *emitter, S64 x)
template<>
struct IRContractAdder<StringView>

Public Static Functions

static inline U32 add(IREmitter *emitter, StringView sv)
template<>
struct IRContractAdder<TableSchema*>

Public Static Functions

static inline U32 add(IREmitter *emitter, TableSchema *schema)
template<>
struct IRContractAdder<U32>

Public Static Functions

static inline U32 add(IREmitter *emitter, U32 ip)
template<typename T>
struct IRContractGetter
#include <ir.hpp>

Template for getting operand values from the emitter store.

template<>
struct IRContractGetter<S64>

Public Static Functions

template<typename Store>
static inline S64 get(Store *emitter, U32 op)

Retrieves an integer from the emitter.

Parameters:
  • emitter – The emitter.

  • op – The operand index.

Returns:

The integer value.

template<>
struct IRContractGetter<StringView>

Public Static Functions

template<typename Store>
static inline StringView get(Store *emitter, U32 op)

Retrieves a string view from the emitter.

Parameters:
  • emitter – The emitter.

  • op – The operand index.

Returns:

The string view.

template<>
struct IRContractGetter<TableSchema*>

Public Static Functions

template<typename Store>
static inline TableSchema *get(Store *emitter, U32 op)

Retrieves a table schema pointer from the emitter.

Parameters:
  • emitter – The emitter.

  • op – The operand index.

Returns:

The table schema pointer.

template<>
struct IRContractGetter<U32>

Public Static Functions

template<typename Store>
static inline U32 get(Store *emitter, U32 op)

Retrieves a raw U32 operand.

Parameters:
  • emitter – The emitter (unused).

  • op – The operand value.

Returns:

The operand value.

struct IREmitter
#include <ir.hpp>

Emits IR instructions during compilation.

Public Functions

IREmitter() = default
inline explicit IREmitter(Allocator *allocator)

Constructs a new IREmitter.

Parameters:

allocator – The allocator to use.

inline U32 gen_temp()

Generates a new unique temporary variable name.

Returns:

Index of the name in the strings pool.

inline U32 add_string(String string)

Adds a string to the strings pool.

Parameters:

string – The string to add.

Returns:

The index of the string.

inline U32 add_string(StringView sv)

Adds a string view to the strings pool.

Parameters:

sv – The string view to add.

Returns:

The index of the string.

inline U32 add_int(S64 integer)

Adds an integer to the integers pool.

Parameters:

integer – The integer to add.

Returns:

The index of the integer.

inline U32 add_schema(TableSchema *schema)

Adds a table schema to the schemas pool.

Parameters:

schema – The schema to add.

Returns:

The index of the schema.

inline U32 add_instruction(IRInstruction instr)

Appends an instruction to the IR.

Parameters:

instr – The instruction to add.

Returns:

The index of the instruction.

Public Members

Allocator *allocator

The allocator.

U32 temps_count = 0

Count of temporary variables.

List<IRInstruction> instructions

The list of instructions.

List<Token> tokens

Tokens associated with instructions.

List<String> strings

The string pool.

List<S64> integers

The integer pool.

List<TableSchema*> schemas

The schema pool.

struct IRInstruction
#include <ir.hpp>

Represents a single instruction in the IR.

Public Functions

inline bool is_table_generating() const

Checks if the instruction generates a new table.

Returns:

true if table-generating, false otherwise.

Public Members

IRInstructionOperator op

The opcode.

U32 operand1

First operand.

U32 operand2

Second operand.

U32 operand3

Third operand.

struct Lexer
#include <Lexer.hpp>

Lexical analyzer for SQL source code.

Public Functions

inline explicit Lexer(String source)

Constructs a Lexer from an ok::String.

Parameters:

source – The source string.

inline explicit Lexer(StringView source)

Constructs a Lexer from an ok::StringView.

Parameters:

source – The source string view.

Optional<Token> next()

Retrieves the next token from the source.

Returns:

An optional containing the next token, or empty if end of source.

template<typename F>
inline StringView take_while(F pred)

Consumes characters while a predicate is true and returns them as a view.

Template Parameters:

F – Type of the predicate function.

Parameters:

pred – The predicate function.

Returns:

A string view of the consumed characters.

template<typename F>
inline void skip_while(F pred)

Skips characters while a predicate is true.

Template Parameters:

F – Type of the predicate function.

Parameters:

pred – The predicate function.

inline void skip_whitespace()

Skips all whitespace characters.

Public Members

StringView source

The source string being analyzed.

size_t pos

Current position in the source string.

struct Logger
#include <Logger.hpp>

Abstract base class for loggers.

Subclassed by xmdb::FileLogger

Public Functions

virtual void set_log_level(LogLevel level) = 0

Sets the minimum log level for this logger.

Parameters:

level – The log level to set.

virtual void log(LogLevel level, const char *fmt, va_list args) = 0

Logs a message with a specific level and format.

Parameters:
  • level – The log level of the message.

  • fmt – The format string.

  • args – The variable arguments.

struct MallocAllocator : public ok::Allocator
#include <util.hpp>

An allocator that uses standard malloc/free for memory management.

Public Functions

inline void *raw_alloc(UZ size) override
inline void raw_dealloc(void *ptr, UZ size) override
inline void *raw_resize(void *ptr, UZ old_size, UZ new_size) override
class NativeLibrary

Public Functions

ok::Optional<NativeSymbol> get_symbol(ok::StringView name) const
void unload()

Public Static Functions

static Result<NativeLibrary, ok::String> load(ok::Allocator *allocator, ok::StringView path)

Private Functions

inline NativeLibrary(void *state, ok::StringView path)

Private Members

void *m_state
ok::StringView m_path
class NativeSymbol

Public Functions

NativeSymbol() = default
inline explicit NativeSymbol(void *ptr)
template<typename T>
inline T cast() const

Private Members

void *m_ptr
struct Node

Public Functions

inline bool is_full()
inline bool is_leaf()
inline bool is_root()
inline void set_leaf(bool v)
inline void set_root(bool v)
inline ok::Slice<U64> keys()
inline ok::Slice<U64> children()
inline U64 keys_count()
inline U64 children_count()
inline void add_keys_count(U64 n)
inline void set_keys_count(U64 n)

Public Members

DiskNode *disk
U64 id

Public Static Functions

static inline Node *alloc_without_backing_disk_buffer(ok::Allocator *allocator)
static inline Node *alloc_with_backing_disk_buffer(ok::Allocator *allocator)
class Node
#include <QueryGraph.hpp>

Base class for nodes in the query graph.

Subclassed by xmdb::QueryGraph::AlterUserNode, xmdb::QueryGraph::AtomicNode, xmdb::QueryGraph::CallNode, xmdb::QueryGraph::DeleteTableNode, xmdb::QueryGraph::EmitQueryNode, xmdb::QueryGraph::InsertNode, xmdb::QueryGraph::ReadNode, xmdb::QueryGraph::WriteColumnNode, xmdb::QueryGraph::WriteNode

Public Types

enum class Type

Types of nodes in the graph.

Values:

enumerator READ

Read data from disk.

enumerator WRITE

Write data to disk.

enumerator ALTER_USER

Alter user properties.

enumerator ATOMIC

A group of atomic operations.

enumerator WRITE_COLUMN

Write a value to a column.

enumerator CALL

Call a function.

enumerator INSERT

Insert rows into a table.

enumerator EMIT_QUERY

Emit query results.

enumerator DELETE_TABLE

Delete a table.

Public Functions

Node() = delete
inline Type type() const

Gets the type of the node.

Returns:

The node type.

inline ok::Optional<Node*> next()

Gets the next node in the graph.

Returns:

An optional pointer to the next node.

inline void set_next(Node *node)

Sets the next node in the graph.

Parameters:

node – Pointer to the next node.

Protected Functions

inline Node(Type type)

Protected Attributes

ok::Optional<Node*> m_next = {}
Type m_type
class NoneDBValue : public xmdb::DBValue
#include <DBValue.hpp>

A DBValue representing “no value”.

Public Functions

inline NoneDBValue()
template<typename K, typename V>
class OrderedMap
#include <OrderedMap.hpp>

A map that maintains the order of elements as they were inserted.

Template Parameters:
  • K – The type of keys.

  • V – The type of values.

Public Functions

OrderedMap(ok::Allocator *allocator, U64 capacity = kDefaultCapacity)

Constructs a new OrderedMap.

Parameters:
  • allocator – The allocator to use.

  • capacity – The initial capacity of the map.

Private Members

ok::Allocator *m_allocator
UZ *m_indices
EntryMeta *m_entries_meta
K *m_keys
V *m_values
U64 m_count = {}
U64 m_capacity

Private Static Attributes

static constexpr U64 kDefaultCapacity = 47
struct PagedSeekList
#include <PagedSeekList.hpp>

Provides paged access to a file, allowing efficient seeking and reading.

Public Functions

PagedSeekList(ok::Allocator *allocator, ok::File file, UZ page_size)

Constructs a new PagedSeekList.

Parameters:
  • allocator – The allocator to use for page buffers.

  • file – The backing file to read from.

  • page_size – The size of each page in bytes.

inline void advance(UZ n)

Advances the current file offset.

Parameters:

n – The number of bytes to advance.

ok::Optional<ok::File::ReadError> get_data(U8 **out_data, UZ requested)

Retrieves data at the current file offset.

Parameters:
  • out_data – Pointer to store the address of the data.

  • requested – The number of bytes requested.

Returns:

An optional read error if the operation failed.

ok::Optional<ok::File::ReadError> load_page(UZ offset, U8 **result, UZ *bytes_avail)

Loads a page of data from the file.

Parameters:
  • offset – The file offset to load from.

  • result – Pointer to store the address of the loaded page.

  • bytes_avail – Pointer to store the number of bytes available in the page.

Returns:

An optional read error if the operation failed.

bool is_at_end()

Checks if the current offset is at the end of the file.

Returns:

true if at the end, false otherwise.

void reset()

Resets the file offset and page state to the beginning.

Public Members

ok::Allocator *allocator

The allocator for page buffers.

U8 *current_page = nullptr

Pointer to the currently loaded page.

UZ current_page_avail = 0

Number of bytes available in the current page.

UZ page_offset = 0

The file offset of the current page.

UZ file_offset = 0

The current logical offset in the file.

UZ page_size

The size of each page.

ok::File backing_file

The backing file.

class PairDBValue : public xmdb::DBValue
#include <DBValue.hpp>

Base class for values that consist of a pair of other values.

Subclassed by xmdb::ConcatDBValue

Public Functions

PairDBValue() = delete
inline DBValue *lhs()

Gets the left-hand side value.

Returns:

Pointer to the LHS value.

inline DBValue *rhs()

Gets the right-hand side value.

Returns:

Pointer to the RHS value.

Protected Functions

inline PairDBValue(SQL::Type type, Kind kind, DBValue *lhs, DBValue *rhs)

Protected Attributes

DBValue *m_lhs
DBValue *m_rhs
struct Parser
#include <Parser.hpp>

Parses SQL source code into an Abstract Syntax Tree (AST).

Public Functions

explicit Parser(ok::ArenaAllocator *allocator, StringView source)

Constructs a new Parser.

Parameters:
  • allocator – The arena allocator to use for AST nodes.

  • source – The SQL source string to parse.

Optional<Stmt*> stmt()

Parses a single SQL statement.

Returns:

An optional pointer to the parsed Stmt, or empty on failure.

Optional<UseStmt*> use_stmt()

Parses a USE statement.

Optional<InsertStmt*> insert_stmt()

Parses an INSERT statement.

Optional<UpdateStmt*> update_stmt()

Parses an UPDATE statement.

Optional<DeleteStmt*> delete_stmt()

Parses a DELETE statement.

Optional<DropStmt*> drop_stmt()

Parses a DROP statement.

Optional<CreateStmt*> create_stmt()

Parses a CREATE statement.

Optional<AlterStmt*> alter_stmt()

Parses an ALTER statement.

Optional<SetClause> set_clause()

Parses a SET clause (e.g., in UPDATE).

Optional<Expr*> expression()

Parses a SQL expression.

Optional<Query> query()

Parses a full SQL query (collection of statements).

bool cur_token_is(Token::Type type) const

Checks if the current token matches a specific type.

bool try_expect(Token::Type type)

Attempts to consume the current token if it matches a specific type.

Returns:

true if consumed, false otherwise.

Optional<Token> expect(Token::Type type)

Expects the current token to match a specific type and consumes it. On failure sets the error value.

Returns:

An optional containing the consumed token, or empty on failure.

Optional<Token> get_cur_token()

Gets the current token without consuming it.

Optional<Token> get_cur_token_or_signal_eof()

Gets the current token or signals EOF error if no more tokens.

void set_token_mismatch(Token token, ok::Slice<Token::Type> types)

Sets a token mismatch error.

void set_eof()

Manually sets the parser state to EOF.

inline bool is_eof() const

Checks if the parser has reached the end of the token stream.

Public Members

ok::ArenaAllocator *arena

The allocator for AST nodes.

StringView source

The original SQL source.

ok::Slice<Token> tokens

The tokens.

size_t pos = 0

Current position in the token stream.

Optional<ErrorWithSourceLocation> error

Error information if parsing failed.

class Plugin
#include <Plugin.hpp>

A representation of a dynamic library with specific exported functions and structure.

Public Functions

void install(ok::StringView name)
void unload()
ok::StringView get_last_error()
ok::Optional<PluginCapability> get_capability(ok::StringView name) const
template<typename T, typename ...Args>
T use_capability(PluginCapability capability, Args&&... args)

Public Static Functions

static Result<Plugin*, ok::String> load(ok::Allocator *allocator, const NativeLibrary *native_lib)

Private Types

using LoadHook = int (*)(void*)
using UnloadHook = void (*)(void*)
using InstallHook = void (*)(void*, const char*, const char***, void***, int*)
using GetLastErrorHook = const char *(*)(void*)
using CapabilitiesList = ok::List<ok::Pair<ok::StringView, NativeSymbol>>

Private Functions

inline Plugin(const NativeLibrary *native_lib, void *plugin_state, UnloadHook unload_hook, InstallHook install_hook, GetLastErrorHook get_last_error_hook, CapabilitiesList capabilities)

Private Members

const NativeLibrary *m_native_lib
void *m_plugin_state
ok::Optional<UnloadHook> m_unload_hook
InstallHook m_install_hook
ok::Optional<GetLastErrorHook> m_get_last_error_hook
CapabilitiesList m_capabilities
bool m_installed = {}
class PluginCapability

Public Functions

inline PluginCapability(ok::StringView name, NativeSymbol symbol)
inline ok::StringView name() const
inline NativeSymbol symbol() const

Private Members

ok::StringView m_name
NativeSymbol m_symbol
class PluginManager

Public Functions

explicit PluginManager(ok::Allocator *allocator)
Result<Plugin*, ok::String> get_or_load(ok::StringView path)

Tries to load a plugin from a file.

Parameters:

path – The file path of a plugin.

Returns:

The plugin pointer if the plugin was already loaded, or on a sucessfull load, an error string otherwise.

void unload(Plugin *plugin)
~PluginManager()

Private Members

ok::Allocator *m_allocator
ok::Table<ok::StringView, Plugin*> m_loaded_plugins
struct Png
#include <Png.hpp>

Represents a PNG image with its header and metadata.

Public Members

PngHeader header

The PNG header.

PixelFormat format

The pixel format of the image.

ChunkIndices indices

Indices of disk chunks comprising full PNG image.

struct PngHeader
#include <Png.hpp>

Header of a Png structure.

Public Members

U32 width

Width of the image in pixels.

U32 height

Height of the image in pixels.

struct PositionalSpec

Public Members

U32 idx
const char *name
struct Query
#include <ast.hpp>

Represents a full SQL query.

Public Members

ok::Slice<Stmt*> stmts

The statements in the query.

struct QueryExecutionContext

Context for executing a database query, managing variables, tables, and operations. Note that the execution context does not actually perform any work (despite it’s name) besides setting up all data that is required for a query to be executed. It only appends new nodes to the query_graph field.

Public Functions

DBValue *fetch_var(U32 index)

Fetches a variable value by index.

Parameters:

index – The variable index.

Returns:

Pointer to the DBValue.

void put_var(U32 index, StringView name, DBValue *value)

Puts a value into a variable.

Parameters:
  • index – The variable index.

  • name – The variable name.

  • value – Pointer to the DBValue.

DBValue *fetch_column(DBTable *table, StringView column_name)

Fetches a value from a table column.

Parameters:
  • table – The table to fetch from.

  • column_name – The name of the column.

Returns:

Pointer to the DBValue.

void emit_column(DBTable *table, DBValue *value, StringView column_name)

Emits a column value for a query result.

Parameters:
  • table – The table being emitted from.

  • value – Pointer to the value.

  • column_name – The name of the column in the result.

DBTable *fetch_table(StringView name)

Fetches a table by name.

Parameters:

name – The table name.

Returns:

Pointer to the DBTable.

DBTable *fetch_table(U32 index)

Fetches a table by index.

Parameters:

index – The table index.

Returns:

Pointer to the DBTable.

void put_table(U32 index, DBTable *table)

Stores a table by index.

Parameters:
  • index – The table index.

  • table – Pointer to the DBTable.

void create_table(StringView name, SQL::TableSchema *schema)

Creates a new table based on a schema.

Parameters:
  • name – The table name.

  • schema – Pointer to the table schema.

DBTable *emit_query(U32 index, SQL::ColumnType *column_types)

Emits the results of a query as a new table.

Parameters:
  • index – The query index.

  • column_types – Pointer to the types of the emitted columns.

Returns:

Pointer to the resulting DBTable.

void insert_column(StringView column_name, DBValue *value)

Prepares a column value for insertion.

Parameters:
  • column_name – The name of the column.

  • value – Pointer to the value.

void insert_row()

Signals that a row is ready to be inserted.

void commit_insert(DBTable *table)

Commits pending row insertions to a table.

Parameters:

table – The table to insert into.

void update_column(DBTable *table, StringView column_name, DBValue *value)

Prepares a column update.

Parameters:
  • table – The table to update.

  • column_name – The column to update.

  • value – Pointer to the new value.

void commit_update()

Commits pending updates.

void delete_table(DBTable *table)

Deletes a table.

Parameters:

table – The table to delete.

void create_user(StringView name)

Creates a new database user.

Parameters:

name – The user name.

void alter_user_property(StringView user_name, StringView property_name, DBValue *value)

Prepares an alteration to a user property.

Parameters:
  • user_name – The name of the user.

  • property_name – The property to alter.

  • value – Pointer to the new property value.

void commit_alter_user()

Commits pending user alterations.

DBValue *compare(DBValue *lhs, DBValue *rhs)

Compares two values.

Parameters:
  • lhs – Left-hand side value.

  • rhs – Right-hand side value.

Returns:

Pointer to a DBValue representing the comparison result.

void prepare_call_arg(DBValue *arg)

Prepares an argument for a function call.

Parameters:

arg – Pointer to the argument value.

DBValue *call(StringView fn_name, U64 args_count)

Calls a built-in function.

Parameters:
  • fn_name – The function name.

  • args_count – The number of arguments.

Returns:

Pointer to the result DBValue.

void sync_state()

Syncs changed state (DBPool) to disk.

Warning

If the call to DBPool::sync_to_disk fails, this method will use ‘longjmp’ to transfer control to a safe point.

Public Members

QueryExecutionContext *next

Pointer to the next context in a pool.

StaticStorage *static_storage

Pointer to global static storage.

QueryGraph query_graph

The graph of operations to perform.

ok::Allocator *allocator

The allocator for this execution.

DBUser *user

The user performing the query.

ok::Table<U32, DBValue*> vars

Local variables.

ok::Table<U32, DBTable*> tables

Tables referenced in the query.

List<StringView> insert_column_names

Pending column names for insertion.

List<DBValue*> insert_column_values

Pending column values for insertion.

List<ok::Pair<Slice<StringView>, Slice<DBValue*>>> rows_to_insert

Rows pending insertion.

ok::MultiList<StringView, DBValue*, DBTable*> emitted_columns

Columns emitted for the result.

ok::MultiList<StringView, DBValue*> columns_to_update

Columns pending update.

Optional<QueryGraph::AtomicNode*> alter_user_atomic_node

Atomic node for user alterations.

DBPool *db_pool

The database pool in use.

DBDescriptor *current_db

The database being queried.

Optional<DBTable*> table_to_insert

Target table for insertion.

Optional<DBTable*> table_to_update

Target table for update.

Optional<DBTable*> last_emitted_query

The last table emitted by a query.

List<DBValue*> call_args

Arguments for the next function call.

Optional<ErrorWithSourceLocation> error

Error information if execution failed.

jmp_buf jmpbuf

Jump buffer for error handling.

class QueryGraph
#include <QueryGraph.hpp>

Represents a graph of operations to be performed on the database.

Public Functions

inline explicit QueryGraph(ok::Allocator *allocator)

Constructs a new QueryGraph.

Parameters:

allocator – The allocator to use for nodes.

inline ok::Optional<Node*> root_node() const

Gets the root node of the graph.

Returns:

An optional pointer to the root node.

inline ReadNode *read(U64 offset, U64 size)

Adds a read node to the graph.

Returns:

The added node.

inline WriteNode *write(U64 offset, U64 size)

Adds a write node to the graph.

Returns:

The added node.

inline AtomicNode *atomic()

Adds an atomic node to the graph.

Returns:

The added node.

inline WriteColumnNode *write_column(DBTable *table, UZ idx, DBValue *value)

Adds a write column node to the graph.

Returns:

The added node.

inline CallNode *call(ok::Allocator *allocator, ok::StringView fn_name, Slice<DBValue*> args)

Adds a function call node to the graph.

Returns:

The added node.

inline EmitQueryNode *emit_query(Allocator *allocator, Slice<DBTable*> queried_tables, Slice<StringView> column_names, Slice<DBValue*> column_values, Slice<SQL::ColumnType> column_types)

Adds an emit query node to the graph.

Returns:

The added node.

inline DeleteTableNode *delete_table(DBTable *table)

Adds a delete table node to the graph.

Returns:

The added node.

inline InsertNode *insert(DBTable *table, Slice<StringView> names, Slice<DBValue*> values, UZ rows_count)

Adds an insert node to the graph.

Returns:

The added node.

void reset()

Resets the query graph, clearing all nodes.

Returns:

The added node.

Private Functions

template<typename T, typename ...Args>
inline T *add_generic_node(Args... args)

Private Members

ok::Allocator *m_allocator
ok::Optional<Node*> m_root_node
ok::Optional<Node*> m_last_node
struct QueryResults
#include <DBConnection.hpp>

Stores the results of a database query.

Public Members

Optional<ErrorWithSourceLocation> error

Error information if the query failed.

Optional<DBTable*> value

The resulting table if the query succeeded and had any output.

class ReadNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing a disk read operation.

Public Functions

inline ReadNode(U64 offset, U64 size)
inline U64 size() const
inline U64 offset() const
inline ok::Slice<U8> buffer() const
inline void set_buffer(ok::Slice<U8> buffer)

Private Members

U64 m_size
U64 m_offset
ok::Slice<U8> m_buffer
template<typename TOk, typename TError>
class Result
#include <Result.hpp>

A template class representing either a success value or an error value.

Template Parameters:
  • TOk – The type of the success value.

  • TError – The type of the error value.

Public Functions

inline Result(const TOk &ok)

Constructs a success Result.

Parameters:

ok – The success value.

inline Result(const TError &error)

Constructs an error Result.

Parameters:

error – The error value.

TOk &unwrap()

Unwraps the success value. Panics if the Result is an error.

Returns:

Reference to the success value.

const TOk &unwrap() const

Unwraps the success value (const version). Panics if the Result is an error.

Returns:

Const reference to the success value.

TOk &unwrap_unchecked()

Unwraps the success value without checking if it’s an error.

Returns:

Reference to the success value.

const TOk &unwrap_unchecked() const

Unwraps the success value without checking if it’s an error (const version).

Returns:

Const reference to the success value.

TError &error()

Retrieves the error value. Panics if the Result is success.

Returns:

Reference to the error value.

const TError &error() const

Retrieves the error value (const version). Panics if the Result is success.

Returns:

Const reference to the error value.

TError &error_unchecked()

Retrieves the error value without checking if it’s a success.

Returns:

Reference to the error value.

const TError &error_unchecked() const

Retrieves the error value without checking if it’s a success (const version).

Returns:

Const reference to the error value.

template<typename TResult, typename TOkFn, typename TErrorFn>
TResult match(TOkFn ok_fn, TErrorFn error_fn)

Matches the result using provided functions for success and error cases.

Template Parameters:
  • TResult – The return type of the matching functions.

  • TOkFn – Type of the success function.

  • TErrorFn – Type of the error function.

Parameters:
  • ok_fn – Function to call on success.

  • error_fn – Function to call on error.

Returns:

The result of the called function.

template<typename TResult, typename TOkFn, typename TErrorFn>
TResult match(TOkFn ok_fn, TErrorFn error_fn) const

Matches the result using provided functions (const version).

inline bool ok() const

Checks if the Result is a success.

Returns:

true if success, false if error.

Public Members

TOk ok_val
TError error_val

Private Members

bool m_ok
union xmdb::Result m_u
class RowDescriptor
#include <TableStream.hpp>

Describes a row in a table.

Public Functions

inline ok::Slice<ColumnDescriptor> column_descriptors() const

Gets the collection of column descriptors.

Returns:

A slice of column descriptors.

Private Members

ok::Slice<ColumnDescriptor> m_column_descriptors
struct SDFile
#include <SDFile.hpp>

SD (self-destructing) file is accessible only to the current process and gets deleted on process exit.

Public Members

int fd

The file descriptor.

struct SelectExpr : public xmdb::SQL::Expr
#include <ast.hpp>

Represents a SELECT expression (subquery).

Public Members

ok::Slice<Expr*> exprs

The expressions being selected.

Expr *table

The source table.

Public Static Functions

static inline SelectExpr *alloc(ok::Allocator *allocator, Token token, ok::Slice<Expr*> exprs, Expr *table)

Allocates a new SelectExpr.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • exprs – The expressions being selected.

  • table – The source table expression.

Returns:

Pointer to the new SelectExpr.

template<UZ... Xs>
struct Seq
template<UZ Counter, UZ Max, UZ... Ints>
struct SeqLoop

Public Types

using Type = typename SeqLoop<Counter + 1, Max, Ints..., Counter>::Type
template<UZ Max, UZ... Ints>
struct SeqLoop<Max, Max, Ints...>

Public Types

using Type = Seq<Ints...>
struct SetClause
#include <ast.hpp>

Represents a single assignment in a SET clause.

Public Members

ok::String name

The name of the field.

Expr *value

The value to assign.

struct SHA256Digest
#include <hash.hpp>

Represents a SHA-256 hash digest.

Public Functions

inline bool operator==(const SHA256Digest &other) const

Public Members

ok::Array<U8, SIZE> bytes

The raw bytes of the digest.

Public Static Attributes

static constexpr UZ SIZE = 32

Size of the digest in bytes.

struct SourceLocation
#include <SourceLocation.hpp>

Represents a location within a source file.

Public Functions

inline bool operator==(const SourceLocation &other) const

Public Members

uint32_t line

The line number (1-based).

uint32_t column

The column number (1-based).

uint32_t length

The length of the source fragment.

struct StarExpr : public xmdb::SQL::Expr
#include <ast.hpp>

Represents a star (‘*’) expression.

Public Static Functions

static inline StarExpr *alloc(ok::Allocator *allocator, Token token)

Allocates a new StarExpr.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

Returns:

Pointer to the new StarExpr.

struct StaticStorage
#include <StaticStorage.hpp>

Global storage for built-in functions and other static data.

Public Members

ok::Table<ok::StringView, void*> builtin_functions

Table mapping function names to their implementations.

struct Stmt
#include <ast.hpp>

Base class for all SQL statements in the AST.

Subclassed by xmdb::SQL::AlterStmt, xmdb::SQL::CreateStmt, xmdb::SQL::DeleteStmt, xmdb::SQL::DropStmt, xmdb::SQL::ExprStmt, xmdb::SQL::InsertStmt, xmdb::SQL::UpdateStmt, xmdb::SQL::UseStmt

Public Types

enum Type

Types of SQL statements.

Values:

enumerator USE

USE statement.

enumerator INSERT

INSERT statement.

enumerator UPDATE

UPDATE statement.

enumerator DELETE

DELETE statement.

enumerator DROP

DROP statement.

enumerator CREATE

CREATE statement.

enumerator EXPR

Expression statement.

enumerator ALTER

ALTER statement.

Public Members

Type type

The type of the statement.

Token token

The primary token associated with the statement.

struct StmtGraph

Public Functions

inline explicit StmtGraph(Allocator *allocator)
inline U32 add_expr_node(Expr *expr, StmtGraphNode node)
inline U32 add_stmt_node(StmtGraphNode node)

Public Members

Allocator *allocator
Table<ok::HashPtr<Expr>, U32> node_indices
List<StmtGraphNode> nodes
U32 root_node_index = {}
struct StmtGraphNode

Public Types

enum Type

Values:

enumerator EQ
enumerator LT
enumerator GT
enumerator SELECT
enumerator UPDATE
enumerator INSERT
enumerator DELETE
enumerator LEAF
enumerator STAR

Public Functions

inline Type type() const
inline bool is_visited() const
inline void make_visited()
inline const char *type_pretty() const

Public Members

U32 ir_id = 0
U32 flags
Expr *expr
Stmt *stmt
union xmdb::SQL::StmtGraphNode up
Slice<U32> edges

Public Static Functions

static inline StmtGraphNode expr(Type type, Expr *value, Slice<U32> edges)
static inline StmtGraphNode stmt(Type type, Stmt *stmt, Slice<U32> edges)
class Store
#include <TableStream.hpp>

Base class for table storage backends.

Subclassed by xmdb::DiskStore

Public Functions

Store() = delete
template<typename T>
const T &deref(ColumnDescriptor) = delete

Protected Types

enum class Type

Storage backend type.

Values:

enumerator RAM

In-memory storage.

enumerator DISK

Disk-based storage.

Protected Functions

inline Store(Type type)

Constructs a Store with a specific type.

Parameters:

type – The storage type.

Protected Attributes

Type m_type
struct StreamPair

Public Members

DBTableStream lhs
DBTableStream rhs
struct StringExpr : public xmdb::SQL::Expr
#include <ast.hpp>

Represents a string literal expression.

Public Members

ok::String value

The string value.

Public Static Functions

static inline StringExpr *alloc(ok::Allocator *allocator, Token token, ok::String value)

Allocates a new StringExpr.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • value – The string value.

Returns:

Pointer to the new StringExpr.

struct TableLayout
#include <ColumnLayout.hpp>

Layout information for an entire table record.

Public Members

UZ primary_key_index

The index of the primary key column.

ok::Slice<ColumnLayout> columns

The collection of column layouts.

struct TableObject

Public Members

ok::StringView name
ok::Slice<ok::StringView> column_names
ok::Slice<SQL::ColumnType> column_types
struct TableSchema
#include <ir.hpp>

Represents the schema of a table in the IR.

Public Functions

inline bool find_column(StringView name) const

Checks if a column with the given name exists in the schema.

Parameters:

name – The column name to search for.

Returns:

true if found, false otherwise.

Public Members

List<Optional<String>> columns_names

The names of the columns.

Optional<List<ColumnType>> columns_types

The types of the columns (if typed).

Public Static Functions

static inline TableSchema untyped(Allocator *a)

Creates an untyped table schema.

Parameters:

a – The allocator to use.

Returns:

The new TableSchema.

static inline TableSchema typed(Allocator *a)

Creates a typed table schema.

Parameters:

a – The allocator to use.

Returns:

The new TableSchema.

struct Token
#include <Lexer.hpp>

Represents a single token in SQL source code.

Public Types

enum Type

Types of SQL tokens.

Values:

enumerator XMDB_ENUM_SQL_TOKENS

Public Members

Type type

The type of the token.

StringView data

The literal text of the token in the source.

template<typename A, typename B, typename C>
struct Triple
#include <ir.hpp>

Helper for three values.

Public Members

A op1
B op2
C op3
template<typename A, typename B>
struct Tuple
#include <ir.hpp>

Helper for two values.

Public Members

A op1
B op2
struct TypedCompiledQuery
#include <type_check.hpp>

Result of compiling and type-checking a query.

Public Members

CompiledQuery untyped

The underlying untyped compiled query.

Table<U32, TypedTableSchema> table_types

Mapping of instruction IDs to their resulting table schemas.

struct TypedTableSchema
#include <type_check.hpp>

Schema for a table with typed columns.

Public Members

Slice<Optional<String>> column_names

Names of the columns.

Slice<Type> column_types

Types of the columns.

struct TypeLayout

Public Members

UZ size
UZ alignment

Public Static Attributes

static constexpr UZ MAX_ALIGNMENT = sizeof(UZ)
struct TypingContext
#include <type_check.hpp>

Context for the type-checking phase.

Public Functions

TypingContext(Allocator *allocator, StringView source)

Constructs a new TypingContext.

Parameters:
  • allocator – The allocator to use.

  • source – The original SQL source.

Public Members

Allocator *allocator

The allocator.

Table<U32, Type> ir_instruction_types

Mapping of instruction IDs to their result types.

Table<U32, TypedTableSchema> table_types

Mapping of instruction IDs to table schemas.

Table<StringView, FunctionSignature> function_signatures

Mapping of function names to signatures.

List<U32> emitted_columns

Pending IDs of values emitted as columns of a query.

List<U32> call_args

IDs of values used as function arguments.

List<StringView> insert_column_names

Pending column names for insertion.

List<U32> insert_column_values

Pending value instruction IDs for insertion.

StringView source

The original SQL source (for error reporting).

Optional<ErrorWithSourceLocation> error

Error information if type checking failed.

struct UpdateStmt : public xmdb::SQL::Stmt
#include <ast.hpp>

Represents an UPDATE statement.

Public Members

Expr *table

The table to update.

ok::Slice<ok::String> columns

The columns to update.

ok::Slice<Expr*> values

The new values.

ok::Optional<Expr*> filter

The WHERE clause filter.

Public Static Functions

static inline UpdateStmt *alloc(ok::Allocator *allocator, Token token, Expr *table, ok::Slice<ok::String> columns, ok::Slice<Expr*> values, ok::Optional<Expr*> filter)

Allocates a new UpdateStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • table – The table expression.

  • columns – The columns to update.

  • values – The new values.

  • filter – The filter expression.

Returns:

Pointer to the new UpdateStmt.

struct UseStmt : public xmdb::SQL::Stmt
#include <ast.hpp>

Represents a USE statement.

Public Members

ok::String database

The name of the database to use.

Public Static Functions

static inline UseStmt *alloc(ok::Allocator *allocator, Token token, ok::StringView database)

Allocates a new UseStmt.

Parameters:
  • allocator – The allocator to use.

  • token – The associated token.

  • database – The name of the database.

Returns:

Pointer to the new UseStmt.

class Value
#include <Value.hpp>

Represents a concrete value of a specific SQL type.

Public Types

enum class Type

The type of the value.

Values:

enumerator INT

Integer value.

enumerator BOOL

Boolean value.

enumerator STRING

Fixed string value.

enumerator IMAGE_CHUNK

Image chunk value.

enumerator BIG_STRING

String of size exceeding the maximum size of a fixed string.

Public Functions

Value() = delete
inline S64 as_int()

Retrieves the value as an integer.

Returns:

The integer value.

inline bool as_bool()

Retrieves the value as a boolean.

Returns:

The boolean value.

inline FixedString as_string()

Retrieves the value as a FixedString.

Returns:

The fixed string.

inline const FixedString *as_string_ptr() const

Retrieves the value as a pointer to FixedString.

Returns:

Const pointer to the fixed string.

inline ImageChunk *as_chunk()

Retrieves the value as an ImageChunk pointer.

Returns:

Pointer to the image chunk.

inline ok::String *as_big_string()

Retrieves the value as a pointer to a String.

Returns:

Pointer to the string.

inline Type type() const

Gets the type of the value.

Returns:

The type.

Value compare(Value other)

Compares this value with another value.

Parameters:

other – The other value to compare with.

Returns:

A Value representing the comparison result.

Public Static Functions

static inline Value integer(S64 value)

Creates an integer value.

Parameters:

value – The integer.

Returns:

The resulting Value.

static inline Value boolean(bool value)

Creates a boolean value.

Parameters:

value – The boolean.

Returns:

The resulting Value.

static inline Value string(ok::Allocator *a, FixedString s)

Creates a string value.

Parameters:
  • a – The allocator to use for storing the string.

  • s – The fixed string.

Returns:

The resulting Value.

static inline Value image_chunk(ok::Allocator *a, U64 x, U64 y, U64 width, U64 height, ok::Slice<U8> data, PixelFormat format)

Creates an image chunk value.

Parameters:
  • a – The allocator to use.

  • x – X-coordinate.

  • y – Y-coordinate.

  • width – Width.

  • height – Height.

  • data – Raw pixel data.

  • format – Pixel format.

Returns:

The resulting Value.

static inline Value big_string(ok::Allocator *allocator, ok::StringView data)

Creates a “big string” value.

Parameters:
  • allocator – The allocator to use.

  • data – String data.

Returns:

The resulting Value.

static inline Value greater()

Creates a “greater than” comparison result (integer 1).

Returns:

The resulting Value.

static inline Value less()

Creates a “less than” comparison result (integer -1).

Returns:

The resulting Value.

static inline Value equal()

Creates an “equal” comparison result (integer 0).

Returns:

The resulting Value.

Private Functions

inline Value(Type type, void *data)

Private Members

Type m_type
void *m_data
struct WebArenaAllocator : public ok::Allocator
#include <util.hpp>

An allocator that uses a web_arena for memory management.

Public Functions

inline explicit WebArenaAllocator(web_arena *impl)

Constructs a new WebArenaAllocator.

Parameters:

impl – Pointer to the web_arena implementation.

inline void *raw_alloc(UZ size) override
inline void raw_dealloc(void *ptr, UZ size) override
inline void *raw_resize(void *ptr, UZ old_size, UZ new_size) override

Public Members

web_arena *impl

The underlying web_arena.

class WriteColumnNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing an update to a table column.

Public Functions

inline WriteColumnNode(DBTable *table, UZ idx, DBValue *value)
inline DBTable *table()
inline UZ idx()
inline DBValue *value()

Private Members

DBTable *m_table
UZ m_idx
DBValue *m_value
class WriteNode : public xmdb::QueryGraph::Node
#include <QueryGraph.hpp>

Node representing a disk write operation.

Public Functions

inline WriteNode(U64 offset, U64 size)
inline U64 size() const
inline U64 offset() const

Private Members

U64 m_size
U64 m_offset
namespace ok
namespace literals
namespace xmdb

Typedefs

using BTreeStateFlags = U16
template<typename ...args>
using MakeSeq = typename SeqLoop<0, sizeof...(args)>::Type

Enums

Values:

enumerator FLAG_FIRST_CONSTRUCTION
enum DBUserPermissions

Permissions available for a database user.

Values:

enumerator XMDB_ENUM_USER_PERMISSIONS
enum class PixelFormat

Supported pixel formats for image data.

Values:

enumerator RGB

Red, Green, Blue pixel components, 1 byte for each one.

enum class LogLevel

Severity levels for logging.

Values:

enumerator DEBUG

Fine-grained informational events that are most useful to debug an application.

enumerator INFO

Informational messages that highlight the progress of the application at coarse-grained level.

enumerator WARN

Potentially harmful situations.

enumerator ERROR

Error events that might still allow the application to continue running.

enumerator NONE

Turns off logging.

Functions

template<typename T>
static void write(ok::File *file, const T *value)
Result<UZ, ok::String> catalog_save(ok::Allocator *allocator, DBPool *pool, ok::StringView filename)
template<typename T>
static void read(ok::File *file, T *out)
Result<UZ, ok::String> catalog_load(ok::Allocator *allocator, DBPool *pool, ok::StringView filename)
static inline UZ table_record_size(TableLayout layout)
bool compile_and_execute_source(ok::ArenaAllocator *arena, DBConnection *connection, StringView source, QueryResults *results, String *error)

Compiles and executes SQL source code.

Parameters:
  • arena – The allocator for temporary data during compilation and execution.

  • connection – The database connection to execute the query on.

  • source – The SQL source string to execute.

  • results – Pointer to a structure to store the query results.

  • error – Pointer to a string to store error messages if execution fails.

Returns:

true if compilation and execution succeeded, false otherwise.

void populate_ir_context_from_pool(SQL::IrContext *ctx, DBPool *pool)

Populates the provided IrContext from a DBPool, providing information about existing databases, users and tables.

Parameters:
  • ctx – The IR context.

  • pool – The database pool.

static inline ColumnType type_to_column_type(Type type)
static void execute_instruction(TypedCompiledQuery *query, UZ i, QueryExecutionContext *ctx, DBConnection *conn)
template<typename T>
DBValue *cpp_to_db_value(ok::Allocator*, const T&) = delete
template<>
DBValue *cpp_to_db_value<ImageChunk>(ok::Allocator *allocator, const ImageChunk &image_chunk)
template<typename ...Args>
consteval UZ args_count()
template<typename T>
T extract(Allocator *allocator, DBValue*) = delete
template<UZ Idx, typename T>
T extract(Allocator *allocator, Slice<DBValue*> values)
template<>
U32 extract<U32>(Allocator *allocator, DBValue *db_value)
template<>
StringView extract<StringView>(Allocator *allocator, DBValue *db_value)
template<typename Return, typename ...Args, UZ... I>
Result<Return, ErrorWithSourceLocation> call_impl(SourceLocation location, ok::Allocator *allocator, XMDB_BUILTIN_FUNCTION_SIG_NAME(fn_ptr, Return, Args...), ok::Array<DBValue*, sizeof...(Args)> raw_args, Seq<I...>)
template<typename Return, typename ...Args>
Result<Return, ErrorWithSourceLocation> call(SourceLocation location, ok::Allocator *allocator, XMDB_BUILTIN_FUNCTION_SIG_NAME(fn_ptr, Return, Args...), ok::Array<DBValue*, sizeof...(Args)> raw_args)
static void fill_column(DBRecord *record, DBTable *table, UZ column_index, Value column_value)
static void flush_buffer(QueryExecutionContext *ctx, DBTable *table, ok::Slice<DBRecord> record_buffer)
static void run_single_node(QueryExecutionContext *ctx, QueryGraph::Node *node)
static bool create_file_based_on_table_flags(DBTable::Flags flags, ok::String filename, ok::File *out_file)
Result<UZ, ok::String> sync_db_pool(DBPool *pool)
DBRecord db_record_create(ok::Allocator *allocator, TableLayout layout)

Creates a new DBRecord with a buffer sized according to the table layout.

Parameters:
  • allocator – The allocator to use for the buffer.

  • layout – The layout of the table.

Returns:

The newly created DBRecord.

ColumnAttribute get_attribute_for_column_type(SQL::ColumnType column_type)

Gets an attribute for a column type.

Parameters:

column_type – The column type.

Returns:

The column attribute.

static TypeLayout type_layout(SQL::ColumnType type)
static ColumnLayout *compute_columns_layout(ok::Allocator *allocator, UZ columns_count, SQL::ColumnType *columns_types)
static inline ok::Optional<Value> poll(ok::Allocator *allocator, DBValue *value)
FixedString create_fixed_string(ok::StringView sv)

Creates a FixedString from an ok::StringView.

Parameters:

sv – The string view to convert.

Returns:

The resulting FixedString.

static inline bool operator==(const FixedString &lhs, const ok::StringView &rhs)
static U32 rotr32(U32 x, U32 n)
static void process_chunk(U32 *h, const U8 *chunk)
SHA256Digest sha256_digest(ok::StringView sv)

Computes the SHA-256 digest of a string view.

Parameters:

sv – The string view to hash.

Returns:

The resulting SHA256Digest.

U8 format_pixel_size_in_bytes(PixelFormat format)

Retrieves the size of a single pixel in bytes for a given format.

Parameters:

format – The pixel format.

Returns:

The size in bytes.

static bool check_logger()
void set_logger(Logger *logger)

Sets the global logger instance.

Parameters:

logger – Pointer to the logger to use.

void set_log_level(LogLevel level)

Sets the global log level.

Parameters:

level – The log level to set.

bool sd_file_create(ok::StringView filename, SDFile *out)

Creates a new SDFile with the given filename.

Parameters:
  • filename – The name of the file to create.

  • out – Pointer to store the resulting SDFile.

Returns:

true if successful, false otherwise.

bool db_state_create(ok::File file, DBState *out)

Creates a new table state in the given file.

Parameters:
  • file – The file to use.

  • out – Pointer to store the resulting DBState.

Returns:

true if successful, false otherwise.

bool db_state_sync(DBState *state)

Synchronizes the table state to disk.

Parameters:

state – Pointer to the state to sync.

Returns:

true if successful, false otherwise.

bool db_state_reset(DBState *state)

Resets the table state.

Parameters:

state – Pointer to the state to reset.

Returns:

true if successful, false otherwise.

Result<DBState, ok::String> db_state_load(ok::Allocator *allocator, ok::File file)

Tries to load a DBState from an open file.

Parameters:
  • allocator – The allocator to use for error strings.

  • file – The file to use.

Returns:

A loaded DBState on success, an error string otherwise.

bool image_state_create(ok::File file, ImageColumnState *out)

Creates a new image column state in the given file.

Parameters:
  • file – The file to use.

  • out – Pointer to store the resulting ImageColumnState.

Returns:

true if successful, false otherwise.

Result<ImageColumnState, ok::String> image_state_load(ok::Allocator *allocator, ok::File file)

Loads an existing image column state from an open file.

Parameters:
  • allocator – The allocator to use for error strings.

  • file – The file to use.

Returns:

Loaded ImageColumnState on success, an error string otherwise.

bool image_state_sync(ImageColumnState *state)

Synchronizes the image column state to disk.

Parameters:

state – Pointer to the state to sync.

Returns:

true if successful, false otherwise.

static inline constexpr U64 gen_magic(ok::StringView s)
XMDB_DECLARE_BUILTIN_FUNCTION(RGB, ImageChunk, U32 width, U32 height, ok::StringView hex_data)
StaticStorage *make_or_get_static_storage()

Retrieves the global StaticStorage instance, creating it if it doesn’t exist.

Returns:

Pointer to the StaticStorage instance.

void dief (const char *fmt,...) OK_ATTRIBUTE_PRINTF(1

Terminates the program with a formatted error message.

Parameters:
  • fmt – The format string.

  • ... – The format arguments.

ok::String to_hex_string(ok::Allocator *allocator, ok::Slice<U8> bytes)

Converts a slice of bytes to a hexadecimal string.

Parameters:
  • allocator – The allocator to use for the string.

  • bytes – The bytes to convert.

Returns:

The hexadecimal string.

ok::Optional<ok::Slice<U8>> from_hex_string(ok::Allocator *allocator, ok::StringView sv)

Converts a hexadecimal string back to a slice of bytes.

Parameters:
  • allocator – The allocator to use for the resulting slice.

  • sv – The hexadecimal string.

Returns:

An optional slice of bytes if conversion succeeded.

Variables

constexpr U64 CATALOG_HEADER_MAGIC = gen_magic("cxmdb"_sv)
constexpr U64 CATALOG_VERSION = 1
constexpr U64 BTREE_PAGE_SIZE = 4096
constexpr U16 BTREE_HEADER_VERSION = 1
constexpr U64 BTREE_HEADER_MAGIC = ((U64)'x' << 56) | ((U64)'m' << 48) | ((U64)'d' << 40) | ((U64)'b' << 32)
constexpr U64 BTREE_HEADER_LENGTH = BTREE_PAGE_SIZE
constexpr U64 BTREE_ORDER = 128
constexpr auto BTREE_MAX_KEYS = BTREE_ORDER * 2 - 1
constexpr auto BTREE_MAX_CHILDREN = BTREE_ORDER * 2
constexpr auto DB_STATE_HEADER_LENGTH = sizeof(DBStateHeader)
constexpr UZ DB_RECORD_BUFFER_CAPACITY = 32
constexpr ok::StringView DEFAULT_CATALOG_FILE_NAME = "xmdb.cat"_sv
constexpr bool chunk_images = false
static constexpr U32 K[64] = {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,}
static constexpr U32 INIT[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,}
constexpr UZ MAX_DISK_IMAGE_SIZE = GiB(4)
constexpr UZ MAX_DISK_IMAGE_CHUNK_SIZE = MiB(64)
constexpr UZ MAX_DISK_IMAGE_CHUNK_DATA_SIZE = MAX_DISK_IMAGE_CHUNK_SIZE - sizeof(DiskImageChunk)
constexpr UZ MAX_DISK_IMAGE_CHUNKS_COUNT = MAX_DISK_IMAGE_SIZE / MAX_DISK_IMAGE_CHUNK_SIZE
constexpr UZ MAX_IMAGE_DATA_SIZE = MAX_DISK_IMAGE_CHUNK_DATA_SIZE * MAX_DISK_IMAGE_CHUNKS_COUNT
static bool global_logger_init = false
static Logger *global_logger = nullptr
constexpr U64 DB_STATE_HEADER_MAGIC = ((U64)'s' << 56) | ((U64)'x' << 48) | ((U64)'m' << 40) | ((U64)'d' << 32) | ((U64)'b' << 24)
constexpr U64 COLUMN_STATE_HEADER_MAGIC = gen_magic("ixmdb"_sv)
constexpr UZ IMAGE_COLUMN_STATE_HEADER_SIZE = sizeof(ImageColumnStateHeader)
static char quad_to_hex_table [] = {[0] = '0',[1] = '1',[2] = '2',[3] = '3',[4] = '4',[5] = '5',[6] = '6',[7] = '7',[8] = '8',[9] = '9',[10] = 'A',[11] = 'B',[12] = 'C',[13] = 'D',[14] = 'E',[15] = 'F',}
namespace argparser

Enums

enum class Flag

Values:

enumerator STRING
enumerator INT
enumerator BOOL

Functions

static const char *flag_name_with_prefix(ok::Allocator *allocator, const char *flag_name)
namespace log

Namespace containing logging functions.

Functions

void log (LogLevel level, const char *fmt,...) OK_ATTRIBUTE_PRINTF(2

Logs a message with a specific level.

Parameters:
  • level – The log level.

  • fmt – The format string.

  • ... – The format arguments.

void debug (const char *fmt,...) OK_ATTRIBUTE_PRINTF(1

Logs a debug message.

Parameters:
  • fmt – The format string.

  • ... – The format arguments.

void info (const char *fmt,...) OK_ATTRIBUTE_PRINTF(1

Logs an info message.

Parameters:
  • fmt – The format string.

  • ... – The format arguments.

void warn (const char *fmt,...) OK_ATTRIBUTE_PRINTF(1

Logs a warning message.

Parameters:
  • fmt – The format string.

  • ... – The format arguments.

void error (const char *fmt,...) OK_ATTRIBUTE_PRINTF(1

Logs an error message.

Parameters:
  • fmt – The format string.

  • ... – The format arguments.

namespace plugin

Functions

static inline char *sv_to_cstr(ok::Allocator *allocator, ok::StringView sv)

Variables

constexpr ok::StringView PLUG_LOAD_NAME = "xmdb_plugin_load"_sv
constexpr ok::StringView PLUG_UNLOAD_NAME = "xmdb_plugin_unload"_sv
constexpr ok::StringView PLUG_INSTALL_NAME = "xmdb_plugin_install"_sv
constexpr ok::StringView PLUG_GET_LAST_ERROR_NAME = "xmdb_plugin_get_last_error"_sv
namespace server

Typedefs

using ConnectionId = U64
using Timestamp = time_t

Enums

enum class Protocol

Values:

enumerator HTTP

Functions

Optional<ConnectionData*> get_connection_data(ConnectionId id)
void init_connection_state()
xmdb::DBPool *get_shared_db_pool()
static void free_connection_data(ConnectionData *data)
ConnectionId gen_connection(xmdb::DBDescriptor *db, xmdb::DBUser *user)
static inline Timestamp current_timestamp()
void free_connection(ConnectionId)
DECLARE_HANDLER(connect_handler)
DECLARE_HANDLER(run_query_handler)
DECLARE_HANDLER(get_db_objects_handler)
void run_http_server(U16 port)
ok::Slice<TableObject> get_db_table_objects(ok::Allocator *allocator, DBDescriptor *db)

Variables

static ConnectionId last_connection_id = 0
static xmdb::MallocAllocator shared_alloc = {}
static ok::Table<ConnectionId, ConnectionData*> db_connections_table = ok::Table<ConnectionId, ConnectionData*>::alloc(&shared_alloc)
static ConnectionData *connection_free_list
static xmdb::DBPool *shared_db_pool
static constexpr S64 SECOND = 1
static constexpr S64 MINUTE = 60 * SECOND
static constexpr S64 TIMEOUT_DURATION = 15 * MINUTE
namespace SQL

Typedefs

using TokenTable = Table<StringView, Token::Type>

Enums

enum class ColumnType

Supported types for table columns.

Values:

enumerator X
enumerator XMDB_ENUM_COLUMN_TYPES
enum IRInstructionOperator

Opcodes for IR instructions.

Values:

enumerator ENUM_IR_CONTRACTS
enum Type

Supported SQL data types.

Values:

enumerator TYPE_INT

Integer.

enumerator TYPE_STRING

String.

enumerator TYPE_PNG

PNG image data.

enumerator TYPE_IMAGE_CHUNK

A chunk of an image.

enumerator TYPE_BOOL

Boolean.

enumerator TYPE_NULL

NULL value.

enumerator TYPE_TABLE

A database table.

enumerator TYPE_FLOAT

Single-precision floating point.

enumerator TYPE_DOUBLE

Double-precision floating point.

Functions

__attribute__((constructor)) void init_global_state()
void init_global_state()

Initializes the global state for the SQL subsystem (e.g., token tables).

const char *column_type_to_string(ColumnType type)

Converts a ColumnType to its string representation.

Parameters:

type – The column type.

Returns:

The name of the column type.

ok::Optional<ColumnType> parse_column_type(ok::StringView sv)

Parses a column type from a string view.

Parameters:

sv – The string view to parse.

Returns:

The parsed ColumnType, or empty if unknown.

static inline ENUM_IR_CONTRACTS bool compile_use_stmt (UseStmt *stmt, IrContext *ctx)
static Optional<U32> compile_expr(Expr*, IrContext*)
static Optional<U32> compile_ident(IdentifierExpr *ident, IrContext *ctx)
static inline bool parse_type(StringView input, Token where, IrContext *ctx, ColumnType *out)
static inline bool compile_create_stmt(CreateStmt *stmt, IrContext *ctx)
static inline bool compile_drop_stmt(DropStmt *stmt, IrContext *ctx)
static bool compile_alter_stmt(AlterStmt *alter, IrContext *ctx)
static inline bool compile_unoptimizable_stmt(Stmt *stmt, IrContext *ctx)
static U32 expr_to_node(StmtGraph *g, Expr *expr)
static StmtGraph build_expr_stmt_graph(Allocator *allocator, ExprStmt *stmt)
static StmtGraph build_insert_stmt_graph(Allocator *allocator, InsertStmt *stmt)
StmtGraph build_update_stmt_graph(Allocator *allocator, UpdateStmt *stmt)
static StmtGraph build_delete_stmt_graph(Allocator *allocator, DeleteStmt *stmt)
static StmtGraph build_statement_graph(Allocator *allocator, Stmt *stmt)
static inline bool is_stmt_graph_optimizable(Stmt *stmt)
static void to_string(ok::String *string, StmtGraph *g, U32 node_idx, bool type_only = false)
Optional<Slice<U32>> compile_graph_node(StmtGraph *g, U32 node_id, IrContext *ctx)
Optional<U32> compile_graph_node_single(StmtGraph *g, U32 node_id, IrContext *ctx)
static inline bool compile_graph(StmtGraph *graph, IrContext *ctx)
const char *stringify_op(StringView op)
const char *stringify_op(S64 op)
const char *stringify_op(TableSchema *op)
String stringify_ir(Allocator *allocator, CompiledQuery *query)

Stringifies a compiled query.

Parameters:
  • allocator – The allocator to use for the string.

  • query – The compiled query.

Returns:

The human-readable IR string.

bool ir_compile_query(Query *in_query, IrContext *ctx, CompiledQuery *out_query)

Compiles a query AST to IR.

Parameters:
  • in_query – The input query AST.

  • ctx – The IR context.

  • out_query – Pointer to store the compiled query.

Returns:

true if successful, false otherwise.

static inline const char *ir_instruction_operator_name(IRInstructionOperator op)

Gets the name of an IR instruction operator.

Parameters:

op – The instruction operator.

Returns:

The name string.

static inline SourceLocation locate_token(StringView source, Token token)

Calculates the source location of a given token.

Parameters:
  • source – The full source string.

  • token – The token to locate.

Returns:

The source location information.

inline StringView token_type_to_string_view(Token::Type type)

Converts a token type to its human-readable string representation.

Parameters:

type – The token type.

Returns:

A string view of the type name.

Optional<SelectExpr*> parse_select_expr(Parser *p)
Optional<Expr*> parse_expression_prim(Parser *parser)
static inline bool type_is_comparable(Type type)
static inline bool find_column(TypedTableSchema schema, StringView name, Type *type)
static inline bool types_are_equal(Type lhs, Type rhs)
static void error_on(TypingContext *ctx, Token token, String message)
Type column_type_to_type(ColumnType col_type)

Converts a ColumnType to a Type.

Parameters:

col_type – The column type.

Returns:

The corresponding data type.

bool is_image(Type type)

Checks if a type represents image data.

Parameters:

type – The type to check.

Returns:

true if it’s an image type, false otherwise.

const char *type_name(Type type)

Gets the human-readable name of a type.

Parameters:

type – The type.

Returns:

The name string.

static inline bool type_check_ir_instruction(U32 ip, CompiledQuery *ir_emitter, TypingContext *ctx)
bool type_check_query(CompiledQuery *query, TypingContext *ctx, TypedCompiledQuery *out)

Type checks a compiled query.

Parameters:
  • query – The compiled query to check.

  • ctx – The typing context.

  • out – Pointer to store the resulting TypedCompiledQuery.

Returns:

true if successful, false otherwise.

template<typename T>
Type cpp_to_tt() = delete
template<>
Type cpp_to_tt<ok::StringView>()
template<>
Type cpp_to_tt<U32>()
template<>
Type cpp_to_tt<ImageChunk>()
template<typename ...Args>
Slice<Type> cpp_to_tt_multiple(ok::Allocator *allocator)
static inline String format_error(ok::Allocator *allocator, SourceLocation location, ok::StringView message)

Formats an error message with its source location.

Parameters:
  • allocator – The allocator to use for the resulting string.

  • location – The source location of the error.

  • message – The error message.

Returns:

The formatted error string.

Variables

const char * column_type_to_string_table [] = {#define X(type)XMDB_ENUM_COLUMN_TYPES}
TokenTable token_table = {}
StringView token_types_pretty [] = {#define X(str, tok)XMDB_ENUM_SQL_TOKENS}
namespace SQL
file ArgParser.cpp
#include “ArgParser.hpp
file ArgParser.hpp
#include <Core/ok.hpp>
#include <Core/util.hpp>
file BTreeIndex.cpp
#include “BTreeIndex.hpp
#include “Logger.hpp
#include “constants.hpp
file BTreeIndex.hpp
#include “ok.hpp”
file catalog.cpp
#include “catalog.hpp
#include “DBPool.hpp
#include “DBDescriptor.hpp
#include “FixedString.hpp
#include “Logger.hpp
file catalog.hpp
#include “ok.hpp”
#include “state.hpp
file ColumnLayout.hpp
file constants.hpp
#include “state.hpp

Defines

KiB(x)
MiB(x)
GiB(x)
file Core.cpp
#include “Core.hpp
#include <SQL/SQL.hpp>
#include <SQL/util.hpp>
file Core.hpp
#include “DBConnection.hpp
file DBConnection.cpp
#include “DBConnection.hpp
#include “Logger.hpp
#include “DBRecord.hpp
#include “constants.hpp
#include “Result.hpp
#include “image.hpp
#include “Png.hpp
#include <SQL/ir.hpp>
#include <SQL/util.hpp>
#include <csetjmp>

Defines

X(name, ret, ...)
file DBConnection.hpp
#include <SQL/ir.hpp>
#include “DBPool.hpp
#include “ok.hpp”
file DBDescriptor.cpp
#include “DBDescriptor.hpp
#include “new.hpp
#include “Logger.hpp
#include “SDFile.hpp
#include “state.hpp
file DBDescriptor.hpp
#include “DBTable.hpp
#include “DBUser.hpp
file DBPool.cpp
#include “DBPool.hpp
#include “Logger.hpp
#include “catalog.hpp
file DBPool.hpp
#include “DBValue.hpp
#include “DBTable.hpp
#include “ok.hpp”
file DBRecord.cpp
#include “DBRecord.hpp
#include “FixedString.hpp
file DBRecord.hpp
#include “ok.hpp”
#include “Value.hpp
file DBTable.cpp
#include “DBTable.hpp
#include “FixedString.hpp
#include “new.hpp
#include “Logger.hpp
#include “Png.hpp
#include “constants.hpp
file DBTable.hpp
#include “BTreeIndex.hpp
#include “DBValue.hpp
#include “ColumnLayout.hpp
#include “ok.hpp”
#include “Value.hpp
#include “state.hpp
file DBUser.cpp
#include “DBUser.hpp
file DBUser.hpp
#include “hash.hpp
#include “ok.hpp”

Defines

XMDB_ENUM_USER_PERMISSIONS
X(name, value)
file DBValue.cpp
#include “DBValue.hpp
file DBValue.hpp
#include <SQL/type_check.hpp>
#include “ColumnLayout.hpp
#include “image.hpp
file FixedString.cpp
#include “FixedString.hpp
file FixedString.hpp
#include “ok.hpp”
file hash.cpp
#include “hash.hpp
#include <cstring>
file hash.hpp
#include “ok.hpp”
file image.cpp
#include “image.hpp
file image.hpp
#include “constants.hpp
file Logger.cpp
#include “Logger.hpp

Defines

LOG(lvl)
file Logger.hpp
#include “ok.hpp”

Defines

XMDB_FIXME(msg)
file new.hpp
#include “ok.hpp”

Functions

inline void *operator new(UZ n, ok::Allocator *allocator) noexcept

Placement new operator that uses an ok::Allocator.

Parameters:
  • n – The size to allocate.

  • allocator – The allocator to use.

Returns:

Pointer to the allocated memory.

inline void operator delete(void *ptr, ok::Allocator *allocator, UZ size) noexcept

Placement delete operator matching the placement new with ok::Allocator.

Parameters:
  • ptr – Pointer to the memory to deallocate.

  • allocator – The allocator used for allocation.

  • size – The size of the allocation.

file numeric.hpp

Defines

XMDB_MAKE_DISTINCT_NUMERIC(type, underlying)

Macro to create a distinct numeric type that wraps an underlying type. This provides type safety by preventing accidental mixing of different numeric contexts.

XMDB_DECLARE_FLAGS(name, underlying)

Macro to declare a type-safe flags class.

file ok.cpp
#include “ok.hpp”

Defines

OK_IMPLEMENTATION
file OrderedMap.hpp
#include “numeric.hpp
file PagedSeekList.hpp
#include “ok.hpp”
file Png.hpp
#include “image.hpp
file QueryExecutionContext.cpp
#include “new.hpp
#include “Logger.hpp
#include “constants.hpp
#include “Png.hpp

Defines

X(p, _unused)
file QueryExecutionContext.hpp
#include <csetjmp>
#include “util.hpp
#include “DBDescriptor.hpp
#include “DBTable.hpp
#include “DBValue.hpp
#include “DBRecord.hpp
#include “QueryGraph.hpp
#include “StaticStorage.hpp

Defines

XMDB_FAIL(ctx, msg)
XMDB_FAIL_FMT(ctx, fmt, ...)
file QueryGraph.cpp
#include “QueryGraph.hpp
#include “Logger.hpp
#include “new.hpp
file QueryGraph.hpp
#include “ok.hpp”
#include “new.hpp
#include “DBValue.hpp
#include “DBTable.hpp
file Result.hpp
file SDFile.cpp
#include “SDFile.hpp
#include “Logger.hpp
file SDFile.hpp
#include “ok.hpp”
file SourceLocation.hpp
#include “ok.hpp”
file state.cpp
#include “state.hpp
#include “Logger.hpp
#include “Result.hpp
file state.hpp
#include “ok.hpp”
#include “Result.hpp
file StaticStorage.cpp
#include “StaticStorage.hpp
#include “util.hpp
#include “Result.hpp
#include <SQL/ir.hpp>

Defines

FAIL(loc, msg)
FAIL_FMT(loc, msg, ...)
XMDB_DECLARE_BUILTIN_FUNCTION(name, ret, ...)
X(fn_name, ret, ...)
file StaticStorage.hpp
#include “ok.hpp”
file TableStream.hpp
#include “PagedSeekList.hpp
#include “constants.hpp
#include “ok.hpp”
file util.cpp
#include “util.hpp
#include “ok.hpp”
file Value.hpp
#include <SQL/type_check.hpp>
#include “ColumnLayout.hpp
#include “FixedString.hpp
#include “image.hpp
file NativeLibrary.cpp
#include “NativeLibrary.hpp
#include “util.hpp
file NativeLibrary.hpp
#include <Core/ok.hpp>
#include <Core/Result.hpp>
file Plugin.cpp
#include “Plugin.hpp
#include <Core/new.hpp>
#include “util.hpp
file Plugin.hpp
#include <Core/ok.hpp>
#include <Core/Result.hpp>
#include “NativeLibrary.hpp
file PluginManager.cpp
#include “PluginManager.hpp
file PluginManager.hpp
#include <Core/ok.hpp>
#include “Plugin.hpp
file util.hpp
#include “SourceLocation.hpp
#include “ok.hpp”
#include <common.h>

Defines

TRY(x)
file util.hpp
#include <Core/ok.hpp>
file util.hpp
#include “Lexer.hpp
file Config.cpp
#include “Config.hpp
#include <Core/util.hpp>
file Config.hpp
#include <Core/ok.hpp>
file connection.cpp
#include “connection.hpp
file connection.hpp
file http.cpp
#include <cmath>
#include <Core/Core.hpp>
#include <Core/ok.hpp>
#include <http.h>
#include <log.h>
#include “connection.hpp
#include “http.hpp
#include “obj.hpp

Defines

DECLARE_HANDLER(name)
FAIL(status, reason)
file http.hpp
file main.cpp
#include <cmath>
#include <Core/ok.hpp>
#include <Core/util.hpp>
#include <Core/hash.hpp>
#include <Core/Result.hpp>
#include <Core/image.hpp>
#include <Core/Logger.hpp>
#include <SQL/ir.hpp>
#include <http.h>

Functions

static xmdb::Result<xmdb::ImageChunk, ok::String> parse_image_chunk_from_json_object(ok::Allocator *allocator, web_json_object object)
int main(int argc, char **argv)
file main.cpp
#include <SQL/ir.hpp>
#include <SQL/SQL.hpp>
#include <SQL/Parser.hpp>
#include <SQL/util.hpp>
#include <Core/util.hpp>

Functions

void h(int code, const char *msg = nullptr)
void err(const char *why, xmdb::ErrorWithSourceLocation error)
int main(int argc, char **argv)

Variables

const char * help_message  ="ir SOURCE - Usage\n\n""\tSOURCE - xmdb SQL source.\n"
file main.cpp
#include <Core/ok.hpp>
#include <Core/DBPool.hpp>
#include <Core/Core.hpp>
#include <Core/Logger.hpp>
#include “connection.hpp
#include “http.hpp
#include “Config.hpp

Functions

int main(int argc, char **argv)
file obj.cpp
#include “obj.hpp
file obj.hpp
#include <Core/ok.hpp>
#include <SQL/ir.hpp>
file ast.cpp
#include “ast.hpp
#include <Core/ok.hpp>
file ast.hpp
#include <Core/ok.hpp>
#include “Lexer.hpp
file constructor_linux.cpp
#include “Lexer.hpp

Defines

X(str, kw)
file global_state.hpp
file ir.cpp
#include <Core/ok.hpp>
#include <Core/util.hpp>
#include “ir.hpp

Defines

X(type)
X(type)
INSTR_VAR_0(name)
INSTR_VAR_1(name, t1)
INSTR_VAR_2(name, t1, t2)
INSTR_0(name)
INSTR_1(name, t1)
INSTR_2(name, t1, t2)
INSTR_3(name, t1, t2, t3)
INSTR_VAR_2(name, t1, t2)
INSTR_VAR_1(name, t1)
INSTR_VAR_0(name)
INSTR_0(name)
INSTR_1(name, t1)
INSTR_2(name, t1, t2)
INSTR_3(name, t1, t2, t3)
file ir.hpp
#include <Core/ok.hpp>
#include <Core/util.hpp>
#include <Core/image.hpp>
#include “ast.hpp

Defines

XMDB_ENUM_COLUMN_TYPES
X(type)
ENUM_IR_CONTRACTS
INSTR_0(instr)
INSTR_VAR_0(instr)
INSTR_1(instr, _op1)
INSTR_VAR_1(instr, _op1)
INSTR_2(instr, _op1, _op2)
INSTR_VAR_2(instr, _op1, _op2)
INSTR_3(instr, _op1, _op2, _op3)
INSTR_VAR_3(instr, _op1, _op2, _op3)
INSTR_0(instr)
INSTR_VAR_0(instr)
INSTR_1(instr, _op1)
INSTR_VAR_1(instr, _op1)
INSTR_2(instr, _op1, _op2)
INSTR_VAR_2(instr, _op1, _op2)
INSTR_3(instr, _op1, _op2, _op3)
INSTR_VAR_3(instr, _op1, _op2, _op3)
XMDB_ENUM_BUILTIN_FUNCTIONS
XMDB_BUILTIN_FUNCTION_SIG_NAME(name, ret, ...)
XMDB_BUILTIN_FUNCTION_SIG(ret, ...)
INSTR_VAR_0(name)
INSTR_VAR_1(name, t1)
INSTR_VAR_2(name, t1, t2)
INSTR_0(name)
INSTR_1(name, t1)
INSTR_2(name, t1, t2)
INSTR_3(name, t1, t2, t3)
file Lexer.cpp
#include “Lexer.hpp
#include <cctype>

Defines

X(str, tok)
file Lexer.hpp
#include <Core/ok.hpp>
#include <stddef.h>

Defines

XMDB_ENUM_SQL_KEYWORDS
XMDB_ENUM_SQL_TOKENS
X(_t, t)
file Parser.cpp
#include “Parser.hpp
#include <Core/ok.hpp>
#include <Core/util.hpp>
#include <SQL/ast.hpp>

Defines

SET_TOKEN_MISMATCH(p, got, ...)
file Parser.hpp
#include <Core/util.hpp>
#include “Lexer.hpp
#include “ast.hpp
file SQL.cpp
#include “SQL.hpp
#include “Parser.hpp
#include “type_check.hpp
#include “util.hpp
file SQL.hpp
#include “type_check.hpp

SQL convenience routines.

file type_check.cpp
#include “type_check.hpp
#include <SQL/ir.hpp>

Defines

X(fn_name, ret_type, ...)
file type_check.hpp
#include <Core/util.hpp>
#include “ir.hpp
file wasm_module.cpp
#include “stb_sprintf.h”
#include <Core/ok.hpp>
#include <SQL/util.hpp>
#include <SQL/Lexer.cpp>
#include <SQL/Parser.cpp>

Defines

STB_SPRINTF_IMPLEMENTATION
OK_VSNPRINTF
OK_ALLOC_PAGE(sz)
OK_DEALLOC_PAGE(page, sz)
OK_LOG
OK_LOG_ERROR
OK_NO_STDLIB
OK_IMPLEMENTATION

Functions

void *module_alloc(unsigned long size)
void console_log(const char *fmt, ...)
void console_error(const char *fmt, ...)
bool sql_parse_source(const char *source, UZ count, UZ *line, UZ *col, U8 *err_buf, UZ err_buf_count)
group SQL_API
dir src/ArgParser
dir src/CLI
dir src/Core
dir src/IR
dir src/Plugin
dir src/Server
dir src/SQL
dir src
dir src/WASMParser