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
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
$last_error
public
string|null
$last_error
= null
$table
public
string
$table
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
selfcreate()
public
create() : bool
Return values
booldate()
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
selfdatetime()
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
selfdecimal()
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
selfdrop()
public
drop() : bool
Return values
boolexists()
public
exists() : bool
Return values
boolget_fields()
public
get_fields() : array<string|int, mixed>
Return values
array<string|int, mixed>get_last_error()
public
get_last_error() : 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
selfint()
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
selfmodify()
ALTER TABLE METHODS - Versione migliorata per SQLite
public
modify([mixed $force_update = false ]) : bool
Parameters
- $force_update : mixed = false
Return values
boolset_primary_key()
public
set_primary_key(array<string|int, mixed> $fields) : self
Parameters
- $fields : array<string|int, mixed>
Return values
selfstring()
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
selftimestamp()
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
selftinyint()
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