criterium 3.1.3

Lightweigt dynamic database queries for rusqlite.
Documentation
// SPDX-FileCopyrightText: 2025 Slatian
//
// SPDX-License-Identifier: LGPL-3.0-only

//! This file contains an example schema for running unit tests on.
//! It is only included when running unit tests.

use crate::sql::Field;
use crate::sql::Table;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ExampleTable {
	Link,
	File,
	TempKeyValueCache,
}

impl Table for ExampleTable {
	fn sql_safe_table_name(&self) -> &str {
		match self {
			Self::Link => "links",
			Self::File => "files",
			Self::TempKeyValueCache => "temp.key_value_cache",
		}
	}
}

#[allow(dead_code)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ExampleSchema {
	FileId,
	FileName,

	LinkId,
	LinkInFileId,
	LinkToUrl,

	TempKeyValueCacheKey,
	TempKeyValueCacheValue,
}

impl Field for ExampleSchema {
	type TableType = ExampleTable;

	fn sql_safe_field_name(&self) -> &str {
		match self {
			Self::FileId => "file_id",
			Self::FileName => "name",
			Self::LinkId => "link_id",
			Self::LinkInFileId => "in_file_id",
			Self::LinkToUrl => "to_url",
			Self::TempKeyValueCacheKey => "key",
			Self::TempKeyValueCacheValue => "value",
		}
	}

	fn table(&self) -> &Self::TableType {
		match self {
			Self::FileId => &ExampleTable::File,
			Self::FileName => &ExampleTable::File,
			Self::LinkId => &ExampleTable::Link,
			Self::LinkInFileId => &ExampleTable::Link,
			Self::LinkToUrl => &ExampleTable::Link,
			Self::TempKeyValueCacheKey => &ExampleTable::TempKeyValueCache,
			Self::TempKeyValueCacheValue => &ExampleTable::TempKeyValueCache,
		}
	}
}