MilkCore

SchemaSqlite
in package

Database Schema Management Class for SQLite

This class provides a fluent interface for creating and modifying SQLite tables programmatically. It allows for defining fields, indexes, and table properties in a clean, object-oriented way.

Tags
example
// Create a new users table
$schema = Get::schema('#__users');
$schema->id()
    ->string('username', 100)
    ->string('email', 255)
    ->string('password', 255)
    ->int('status', false, 1)
    ->timestamp('created_at')
    ->index('email', 'email')
    ->create();

Table of Contents

Properties

$last_error  : string|null
$table  : string

Methods

__construct()  : mixed
boolean()  : self
create()  : bool
date()  : self
datetime()  : self
decimal()  : self
drop()  : bool
exists()  : bool
get_fields()  : array<string|int, mixed>
get_last_error()  : mixed
id()  : self
Creates an auto-incrementing primary key field
index()  : self
int()  : self
Creates an integer field
longtext()  : self
modify()  : bool
ALTER TABLE METHODS - Versione migliorata per SQLite
set_primary_key()  : self
string()  : self
Creates a string (TEXT) field
text()  : self
Creates a text field
time()  : self
timestamp()  : self
tinyint()  : self
Creates a tiny integer field

Properties

Methods

__construct()

public __construct(string $table[, mixed $db = null ]) : mixed
Parameters
$table : string
$db : mixed = null

boolean()

public boolean(string $name[, bool $null = false ][, bool|null $default = false ][, string|null $after = null ]) : self
Parameters
$name : string
$null : bool = false
$default : bool|null = false
$after : string|null = null
Return values
self

date()

public date(string $name[, bool $null = false ][, string|null $default = null ][, string|null $after = null ]) : self
Parameters
$name : string
$null : bool = false
$default : string|null = null
$after : string|null = null
Return values
self

datetime()

public datetime(string $name[, bool $null = false ][, string|null $default = null ][, string|null $after = null ]) : self
Parameters
$name : string
$null : bool = false
$default : string|null = null
$after : string|null = null
Return values
self

decimal()

public decimal(string $name[, int $precision = 10 ][, int $scale = 2 ][, bool $null = false ][, float|null $default = null ][, string|null $after = null ]) : self
Parameters
$name : string
$precision : int = 10
$scale : int = 2
$null : bool = false
$default : float|null = null
$after : string|null = null
Return values
self

get_fields()

public get_fields() : array<string|int, mixed>
Return values
array<string|int, mixed>

id()

Creates an auto-incrementing primary key field

public id([string $name = 'id' ]) : self

In SQLite, this creates an INTEGER PRIMARY KEY which is automatically AUTOINCREMENT

Parameters
$name : string = 'id'

The name of the primary key field (default: 'id')

Return values
self

Returns the Schema instance for method chaining

index()

public index(string $name[, array<string|int, mixed> $columns = [] ][, bool $unique = false ]) : self
Parameters
$name : string
$columns : array<string|int, mixed> = []
$unique : bool = false
Return values
self

int()

Creates an integer field

public int(string $name[, bool $null = false ][, int|null $default = null ][, string|null $after = null ]) : self
Parameters
$name : string

The name of the field

$null : bool = false

Whether the field can be NULL (default: false)

$default : int|null = null

The default value for the field (default: null)

$after : string|null = null

Not used in SQLite (kept for compatibility)

Return values
self

Returns the Schema instance for method chaining

longtext()

public longtext(string $name[, bool $null = false ][, string|null $after = null ]) : self
Parameters
$name : string
$null : bool = false
$after : string|null = null
Return values
self

modify()

ALTER TABLE METHODS - Versione migliorata per SQLite

public modify([mixed $force_update = false ]) : bool
Parameters
$force_update : mixed = false
Return values
bool

set_primary_key()

public set_primary_key(array<string|int, mixed> $fields) : self
Parameters
$fields : array<string|int, mixed>
Return values
self

string()

Creates a string (TEXT) field

public string(string $name[, int $length = 255 ][, bool $null = false ][, string|null $default = null ][, string|null $after = null ]) : self

In SQLite, VARCHAR is mapped to TEXT

Parameters
$name : string

The name of the field

$length : int = 255

Not used in SQLite (kept for compatibility)

$null : bool = false

Whether the field can be NULL (default: false)

$default : string|null = null

The default value for the field (default: null)

$after : string|null = null

Not used in SQLite (kept for compatibility)

Return values
self

Returns the Schema instance for method chaining

text()

Creates a text field

public text(string $name[, bool $null = false ][, string|null $after = null ]) : self
Parameters
$name : string

The name of the field

$null : bool = false

Whether the field can be NULL (default: false)

$after : string|null = null

Not used in SQLite (kept for compatibility)

Return values
self

Returns the Schema instance for method chaining

time()

public time(string $name[, bool $null = false ][, string|null $default = null ][, string|null $after = null ]) : self
Parameters
$name : string
$null : bool = false
$default : string|null = null
$after : string|null = null
Return values
self

timestamp()

public timestamp(string $name[, bool $null = false ][, string|null $default = 'CURRENT_TIMESTAMP' ][, string|null $after = null ]) : self
Parameters
$name : string
$null : bool = false
$default : string|null = 'CURRENT_TIMESTAMP'
$after : string|null = null
Return values
self

tinyint()

Creates a tiny integer field

public tinyint(string $name[, bool $null = false ][, int|null $default = null ][, string|null $after = null ]) : self

In SQLite, this is mapped to INTEGER

Parameters
$name : string

The name of the field

$null : bool = false

Whether the field can be NULL (default: false)

$default : int|null = null

The default value for the field (default: null)

$after : string|null = null

Not used in SQLite (kept for compatibility)

Return values
self

Returns the Schema instance for method chaining


        
On this page

Search results