index/src/Data/IDbResult.php

118 lines
3.5 KiB
PHP
Raw Normal View History

2022-09-13 13:13:11 +00:00
<?php
// IDbResult.php
// Created: 2021-05-02
2024-02-06 21:39:36 +00:00
// Updated: 2024-02-06
2022-09-13 13:13:11 +00:00
namespace Index\Data;
use Index\ICloseable;
use Index\IO\Stream;
/**
* Represents a database result set.
*/
interface IDbResult extends ICloseable {
/**
* Fetches the next result set.
*
* @return bool true if the result set was loaded, false if no more results are available.
*/
function next(): bool;
/**
* Checks if a given index has a NULL value.
*
* @param int|string $index Target index.
* @return bool true if the value is null, false if not.
*/
function isNull(int|string $index): bool;
/**
* Gets the value from the target index without any additional casting.
*
* @param int|string $index Target index.
* @return mixed Target value.
*/
function getValue(int|string $index): mixed;
/**
* Gets the value from the target index cast as a native string.
*
* @param int|string $index Target index.
* @return string Returns a string of the value.
*/
function getString(int|string $index): string;
2023-11-09 13:52:12 +00:00
/**
* Checks if the field is null, then gets the value from the target index cast as a native string.
*
* @param int|string $index Target index.
* @return ?string Returns a string of the value or null.
*/
function getStringOrNull(int|string $index): ?string;
2022-09-13 13:13:11 +00:00
/**
* Gets the value from the target index cast as an integer.
*
* @param int|string $index Target index.
* @return int Returns the value cast to an integer.
*/
function getInteger(int|string $index): int;
2023-11-09 13:52:12 +00:00
/**
* Checks if the field is null, then gets the value from the target index cast as an integer.
*
* @param int|string $index Target index.
* @return int Returns the value cast to an integer or null.
*/
function getIntegerOrNull(int|string $index): ?int;
2022-09-13 13:13:11 +00:00
/**
* Gets the value from the target index cast as a floating point number.
*
* @param int|string $index Target index.
* @return float Returns the value cast to a floating point number.
*/
function getFloat(int|string $index): float;
2023-11-09 13:52:12 +00:00
/**
* Checks if the field is null, then gets the value from the target index cast as a floating point number.
*
* @param int|string $index Target index.
* @return float Returns the value cast to a floating point number or null.
*/
function getFloatOrNull(int|string $index): ?float;
2023-11-09 14:04:39 +00:00
/**
* Gets the value from the target index cast as a boolean value.
*
* @param int|string $index Target index.
* @return bool Returns the value cast to a boolean value.
*/
function getBoolean(int|string $index): bool;
/**
* Checks if the field is null, then gets the value from the target index cast as a boolean value.
*
* @param int|string $index Target index.
* @return ?bool Returns the value cast to a boolean value or null.
*/
function getBooleanOrNull(int|string $index): ?bool;
2022-09-13 13:13:11 +00:00
/**
* Gets the value from the target index as a Stream.
*
* @param int|string $index Target index.
* @return ?Stream A Stream if data is available, null if not.
*/
function getStream(int|string $index): ?Stream;
2024-02-06 21:39:36 +00:00
/**
* Creates an iterator for this result.
*
* @param callable(IDbResult): object $construct Result info constructor.
* @return DbResultIterator Result iterator.
*/
function getIterator(callable $construct): DbResultIterator;
2022-09-13 13:13:11 +00:00
}