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.
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.
public
static
resolveConnection ($connection = null
)
Property | Type | Description |
---|---|---|
$connection | mixed |
mixed
|
protected arraySourceCanStoreDb () : bool
Determines if the temporary SQLite database for this model's array records will be stored.
protected arraySourceCreateDb () : void
Creates the array source.
This will create the temporary SQLite table and populate it with the given records.
protected arraySourceCreateTable () : void
Creates the temporary SQLite table.
protected arraySourceDbNeedsUpdate () : bool
Determines if the stored array DB should be updated.
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.
protected arraySourceGetDbDir () : string | false
Gets the directory where the array databases will be stored.
protected arraySourceGetDbPath () : string
Gets the path where the array database will be stored.
protected arraySourceResolveDatatype (mixed $value) : string
Determines the best column schema type for a given value
Property | Type | Description |
---|---|---|
$value | mixed |
mixed
|
protected static arraySourceSetDbConnection (string $database) : void
Creates a connection to the temporary SQLite datasource.
By default, this will create an in-memory database.
Property | Type | Description |
---|---|---|
$database | string |
string
|