Skip to content

Verse SQL Generator

Bob Magic II edited this page Feb 19, 2022 · 8 revisions

Verse is to help try and avoid needing to write literal SQL inline. The best way to begin a Verse is to ask the database for a fresh one. This will return back a new Verse object pre-configured to that connection.

$SQL = (
	Nether\Database::Get()
	->NewVerse()
	->Select('Users')
	->Where('ID=:ID')
	->Limit(1)
);

$Result = $SQL->Query([ ':ID' => 42 ]);
$Row = $Result->Next();

It is also able to use the Table Class attributes to prepare itself. For this simple user table it is not that big of a deal but where it really helps is when you start using things like InsertUpdate or InsertReuseUnique attributes, as then Verse is able to generate better SQL to make that behaviour work automatically.

$SQL = (
	Nether\Database\Verse::FromMetaInsert('User')
	->Fields([ 'Name' => ':Name' ])
);

$Result = $SQL->Query([ ':Name' => 'Bob' ]);
$User = User::GetByID($Result->LastInsertID());

Clone this wiki locally