You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Database and ORM are <strong>not built into the kernel</strong>. They're capabilities you install when you need them. Install a database capability like <codeclass="bg-gray-100 px-2 py-1 rounded">ForgeDatabaseSQL</code> or an ORM capability like <codeclass="bg-gray-100 px-2 py-1 rounded">ForgeSqlOrm</code>.
851
+
Database and ORM are <strong>not built into the kernel</strong>. They're capabilities you install when you need them. The kernel provides <strong>contracts (interfaces)</strong> for database operations, but these contracts must be implemented by a module.
852
852
</p>
853
+
<pclass="text-gray-600 mb-4">
854
+
<strong>Important:</strong> The kernel provides <codeclass="bg-gray-100 px-2 py-1 rounded">DatabaseConnectionInterface</code> and <codeclass="bg-gray-100 px-2 py-1 rounded">QueryBuilderInterface</code> contracts, but they won't work unless you install a module that implements them. For example:
<li><strong>Raw SQL Queries:</strong> Use <codeclass="bg-gray-100 px-2 py-1 rounded">QueryBuilderInterface</code> or <codeclass="bg-gray-100 px-2 py-1 rounded">DatabaseConnectionInterface</code>directly, even without installing an ORM capability. This is available through the kernel's database contracts.</li>
858
-
<li><strong>Query Builder:</strong> Use the fluent query builder interface for type-safe database operations.</li>
865
+
<li><strong>Raw SQL Queries:</strong> Use <codeclass="bg-gray-100 px-2 py-1 rounded">DatabaseConnectionInterface</code>(requires ForgeDatabaseSQL) or <codeclass="bg-gray-100 px-2 py-1 rounded">QueryBuilderInterface</code>(requires ForgeSqlOrm) for direct database access.</li>
866
+
<li><strong>Query Builder:</strong> Use the fluent query builder interface for type-safe database operations (requires ForgeSqlOrm).</li>
859
867
<li><strong>ORM:</strong> Use the ForgeSqlOrm capability for attribute-based models and relationships.</li>
860
868
</ol>
869
+
870
+
<h3class="text-lg font-semibold mb-3 text-gray-900">Raw SQL Queries with DatabaseConnectionInterface</h3>
861
871
<pclass="text-gray-600 mb-4">
862
-
<strong>Note:</strong> The ORM examples below assume you've installed the <codeclass="bg-gray-100 px-2 py-1 rounded">ForgeSqlOrm</code> capability. Raw queries and query builder are available through the kernel's database contracts.
872
+
When using <codeclass="bg-gray-100 px-2 py-1 rounded">DatabaseConnectionInterface</code>, you have direct access to PDO methods. This requires the <codeclass="bg-gray-100 px-2 py-1 rounded">ForgeDatabaseSQL</code> module to be installed.
$stmt = $this->connection->query("SELECT * FROM users LIMIT 5");
905
+
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
906
+
}
907
+
}</code></pre>
908
+
</div>
909
+
910
+
<h3class="text-lg font-semibold mb-3 text-gray-900">Raw SQL Queries with QueryBuilderInterface</h3>
866
911
<pclass="text-gray-600 mb-4">
867
-
You can use raw SQL queries without installing any ORM capability. The kernel provides <codeclass="bg-gray-100 px-2 py-1 rounded">QueryBuilderInterface</code> and <codeclass="bg-gray-100 px-2 py-1 rounded">DatabaseConnectionInterface</code>for direct database access. This is how migrations work internally.
912
+
When using <codeclass="bg-gray-100 px-2 py-1 rounded">QueryBuilderInterface</code>, you can use raw SQL methods or combine them with the query builder. This requires the <codeclass="bg-gray-100 px-2 py-1 rounded">ForgeSqlOrm</code>module to be installed.
Models extend the <codeclass="bg-gray-100 px-2 py-1 rounded">Model</code> base class and use attributes to define table structure, columns, and relationships. You can also use traits to add common functionality.
Automatically adds <codeclass="bg-gray-100 px-2 py-1 rounded">created_at</code> and <codeclass="bg-gray-100 px-2 py-1 rounded">updated_at</code> timestamp columns to your model. These are automatically managed by the ORM when creating or updating records.
Adds a <codeclass="bg-gray-100 px-2 py-1 rounded">metadata</code> column for storing JSON data. Useful for flexible, schema-less data that doesn't need its own table.
Provides methods for loading and working with relationships. This trait is already included in the <codeclass="bg-gray-100 px-2 py-1 rounded">Model</code> base class, but you can use it explicitly if needed.
<strong>Note:</strong> Forge uses a query builder pattern. Always start with <code>Model::query()</code> to build queries. There are no static methods like <code>all()</code> or <code>find()</code> directly on the Model class.
967
-
</p>
1194
+
<strong>Note:</strong> Forge uses a query builder pattern. Always start with <codeclass="bg-gray-100 px-2 py-1 rounded">Model::query()</code> to build queries. There are no static methods like <codeclass="bg-gray-100 px-2 py-1 rounded">all()</code> or <codeclass="bg-gray-100 px-2 py-1 rounded">find()</code> directly on the Model class. Use <codeclass="bg-gray-100 px-2 py-1 rounded">with()</code> for eager loading relationships, or <codeclass="bg-gray-100 px-2 py-1 rounded">load()</code> for lazy loading on existing instances.
0 commit comments