ArraySource

Array Source trait.

 trait Winter\Storm\Database\Traits\ArraySource

Allows a model's data to be sourced from array or collection data as opposed to a database table, allowing for arbitrary models to be used for widgets or functionality that require models. This trait will create a temporary SQLite table, either in cache or in memory, to house the record data and run any queries.

Inspired by the "Sushi" library by Caleb Porzio (https://github.com/calebporzio/sushi)

Properties

protected static $arraySourceConnection : Illuminate\Database\Connection

Connection. to the SQLite datasource.

Methods

public static bootArraySource () : void

Boots the ArraySource trait.

Returns
void

public getRecords () : Traversable | array

Gets the records stored with this model.

This method may be overwritten to specify a custom data provider. It should always return an array of associative arrays, with column names for keys and a singular value for each column.

Returns
Traversable | array

public static resolveConnection ($connection = null)

Parameters
Property Description
$connection
mixed
Returns
mixed

protected arraySourceCanStoreDb () : bool

Determines if the temporary SQLite database for this model's array records will be stored.

Returns
bool

protected arraySourceCreateDb () : void

Creates the array source.

This will create the temporary SQLite table and populate it with the given records.

Returns
void

protected arraySourceCreateTable () : void

Creates the temporary SQLite table.

Returns
void

protected arraySourceDbNeedsUpdate () : bool

Determines if the stored array DB should be updated.

Returns
bool

protected arraySourceGetChunkSize () : integer

Sets the array chunk size when storing inserts.

Sometimes, SQLite will complain if given too many records to insert at once, so we will split the records up into reasonable chunks and insert them in groups.

Returns
integer

protected arraySourceGetDbDir () : string | false

Gets the directory where the array databases will be stored.

Returns
string | false

protected arraySourceGetDbPath () : string

Gets the path where the array database will be stored.

Returns
string

protected arraySourceResolveDatatype (mixed $value) : string

Determines the best column schema type for a given value

Parameters
Property Description
$value
mixed
Returns
string

protected static arraySourceSetDbConnection (string $database) : void

Creates a connection to the temporary SQLite datasource.

By default, this will create an in-memory database.

Parameters
Property Description
$database
string
Returns
void
Copyright © 2024 Winter CMS