- Work done on many-to-many relations - code must still be refactored out of the EntityTrait.

- Fixed Entity::field("propertyname") function to look for name into @Field() annotation and returns it if it exists.
- A lot of bug fixes made into SQL fragments.
This commit is contained in:
Dave Mc Nicoll committed 2020-04-09 09:50:09 -04:00
1 parent 6e84fc7195
commit c64c7778bd
20 files changed
+220 -105

No files matched your search

+3 -1
View File
@@ -4,6 +4,8 @@ namespace Ulmus\Query;
class Delete extends Fragment {
const SQL_TOKEN = "DELETE";
public int $order = -100;
public bool $quick = false;
@@ -17,7 +19,7 @@ class Delete extends Fragment {
public function render() : string
{
return $this->renderSegments([
'DELETE',
static::SQL_TOKEN,
( $this->top ? sprintf('TOP (%s)', $this->top) : false ),
( $this->priority ?? false ),
( $this->quick ? 'QUICK' : false ),
+3 -1
View File
@@ -4,6 +4,8 @@ namespace Ulmus\Query;
class Explain extends Fragment {
const SQL_TOKEN = "EXPLAIN";
public int $order = -1500;
public bool $extended = false;
@@ -11,7 +13,7 @@ class Explain extends Fragment {
public function render() : string
{
return $this->renderSegments([
"EXPLAIN", $this->extended ? "EXTENDED" : ""
static::SQL_TOKEN, $this->extended ? "EXTENDED" : ""
]);
}
}
+3 -1
View File
@@ -4,6 +4,8 @@ namespace Ulmus\Query;
class From extends Fragment {
const SQL_TOKEN = "FROM";
public int $order = -80;
public array $tables = [];
@@ -27,7 +29,7 @@ class From extends Fragment {
public function render() : string
{
return $this->renderSegments([
'FROM', $this->renderTables(),
static::SQL_TOKEN, $this->renderTables(),
]);
}
+4 -1
View File
@@ -3,6 +3,9 @@
namespace Ulmus\Query;
class GroupBy extends Fragment {
const SQL_TOKEN = "GROUP BY";
public int $order = 70;
public array $groupBy = [];
@@ -22,7 +25,7 @@ class GroupBy extends Fragment {
public function render() : string
{
return $this->renderSegments([
'GROUP BY', implode(", ", $this->groupBy)
static::SQL_TOKEN, implode(", ", $this->groupBy)
]);
}
+2 -1
View File
@@ -3,5 +3,6 @@
namespace Ulmus\Query;
class Having extends Where {
const SQL_TOKEN = "HAVING";
public int $order = 75;
}
+3 -1
View File
@@ -4,6 +4,8 @@ namespace Ulmus\Query;
class Insert extends Fragment {
const SQL_TOKEN = "INSERT";
public int $order = -100;
public bool $quick = false;
@@ -21,7 +23,7 @@ class Insert extends Fragment {
public function render() : string
{
return $this->renderSegments([
'INSERT',
static::SQL_TOKEN,
( $this->priority ?? false ),
( $this->ignore ? 'IGNORE' : false ),
'INTO', $this->renderTable(),
+26 -13
View File
@@ -2,7 +2,11 @@
namespace Ulmus\Query;
use Ulmus\QueryBuilder;
class Join extends Fragment {
const SQL_TOKEN = "JOIN";
const TYPE_LEFT = "LEFT";
const TYPE_RIGHT = "RIGHT";
@@ -14,24 +18,33 @@ class Join extends Fragment {
public bool $outer = false;
public array $joins = [];
public string $attachment = "ON";
public string $side;
public /*string|QueryBuilder*/ $table;
public string $field;
public /*string|QueryBuilder*/ $value;
public /* QueryBuilder */ $queryBuilder;
public function add(string $side, string $table, string $field, $value)
public function __construct(QueryBuilder $queryBuilder) {
$this->queryBuilder = $queryBuilder;
}
public function set(string $side, /* QueryBuilder|string */ $table, string $field, /* QueryBuilder|string */ $value)
{
$this->joins[] = [
'side' => $side,
'table' => $table,
'field' => $field,
'value' => $value,
];
$this->side = $side;
$this->table = $table;
$this->field = $field;
$this->value = $value;
}
public function render() : string
{
return $this->renderSegments([
#'JOIN',
# table,
# 'ON',
# WHERE ! ,
]);
return $this->renderSegments([ $this->side, static::SQL_TOKEN, $this->table, $this->attachment, $this->field, "=", $this->value ]);
}
}
+4 -4
View File
@@ -4,12 +4,12 @@ namespace Ulmus\Query;
class Limit extends Fragment {
public int $order = 80;
const SQL_TOKEN = "LIMIT";
public int $order = 90;
public int $limit = 0;
public string $keyword = "LIMIT %d";
public function set($limit) : self
{
$this->limit = $limit;
@@ -20,7 +20,7 @@ class Limit extends Fragment {
public function render() : string
{
return $this->renderSegments([
sprintf($this->keyword, $this->limit)
static::SQL_TOKEN, $this->limit
]);
}
}
+5 -3
View File
@@ -3,8 +3,10 @@
namespace Ulmus\Query;
class Offset extends Fragment {
public int $order = 81;
const SQL_TOKEN = "OFFSET";
public int $order = 95;
protected int $offset = 0;
@@ -17,7 +19,7 @@ class Offset extends Fragment {
public function render() : string
{
return $this->renderSegments([
'OFFSET', $this->offset,
static::SQL_TOKEN, $this->offset,
]);
}
}
+4 -2
View File
@@ -3,9 +3,11 @@
namespace Ulmus\Query;
class OrderBy extends Fragment {
public int $order = 70;
public int $order = 80;
public array $orderBy = [];
const SQL_TOKEN = "ORDER BY";
public function set(array $order) : self
{
@@ -27,7 +29,7 @@ class OrderBy extends Fragment {
}, $this->orderBy);
return $this->renderSegments([
'ORDER BY', implode(", ", $list)
static::SQL_TOKEN, implode(", ", $list)
]);
}
+3 -1
View File
@@ -14,6 +14,8 @@ class Select extends Fragment {
protected array $fields = [];
const SQL_TOKEN = "SELECT";
public function set($fields) : self
{
$this->fields = is_array($fields) ? $fields : [ $fields ];
@@ -36,7 +38,7 @@ class Select extends Fragment {
{
return $this->renderSegments([
( $this->union ? 'UNION' : false ),
'SELECT',
static::SQL_TOKEN,
( $this->top ? sprintf('TOP (%s)', $this->top) : false ),
implode(', ', $this->fields)
]);
+3 -1
View File
@@ -17,6 +17,8 @@ class Where extends Fragment {
const COMPARISON_IN = "IN";
const COMPARISON_IS = "IS";
const COMPARISON_NULL = "NULL";
const SQL_TOKEN = "WHERE";
public int $order = 50;
@@ -65,7 +67,7 @@ class Where extends Fragment {
}
return $this->renderSegments([
! $this->parent ? "WHERE" : "",
! $this->parent ? static::SQL_TOKEN : "",
implode(" ", $stack)
]);
}