Initial commit: Crafter.DB

Header-only C++26 module library for typed, file-backed tables with
schema reflection, migrations, queries, and crash-safe commits.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-10-17 04:16:51 +02:00
commit bfd0cc261b
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
34 changed files with 7506 additions and 0 deletions

View file

@ -0,0 +1,65 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Crafter.DB:Error;
import std;
export namespace Crafter::DB {
// Root of every exception the library throws. Catch this to handle
// "the table is unusable" uniformly; catch the subclasses to react.
class Error : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};
// A system call failed. `code` carries errno, `path` the file involved.
class IOError : public Error {
public:
IOError(std::string_view what, std::error_code code, std::filesystem::path path)
: Error(std::format("{}: {} ({})", path.string(), what, code.message())), code(code), path(std::move(path)) {}
std::error_code code;
std::filesystem::path path;
};
// The file is not a Crafter.DB table or its header/commit records fail
// validation (bad magic, both commit CRCs wrong, extents outside the file).
class CorruptError : public Error {
public:
using Error::Error;
};
// The compiled struct and the file disagree: same version but a different
// fingerprint (struct changed without bumping `version`), a file newer
// than the code, or no `Previous` chain reaching the file's version.
class SchemaError : public Error {
public:
using Error::Error;
};
// A migration is needed but cannot run: the table was opened read-only or
// with `migrate = false`.
class MigrationError : public Error {
public:
using Error::Error;
};
// Another process (or another Table object in this process) holds the
// file lock in a conflicting mode.
class LockedError : public Error {
public:
using Error::Error;
};
// A write would break the order of the `orderedBy` column.
class OrderError : public Error {
public:
using Error::Error;
};
// A write was attempted on a table opened with `readOnly = true`.
class ReadOnlyError : public Error {
public:
using Error::Error;
};
}