Completed
Push — master ( 47225e...b9101f )
by Arman
18s queued 15s
created

RelationalTrait::query()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.6
13
 */
14
15
namespace Quantum\Libraries\Database\Traits;
16
17
use Quantum\Libraries\Database\Exceptions\DatabaseException;
18
19
/**
20
 * Trait RelationalTrait
21
 * @package Quantum\Libraries\Database
22
 */
23
trait RelationalTrait
24
{
25
26
    /**
27
     * Raw execute
28
     * @param string $query
29
     * @param array $parameters
30
     * @return bool
31
     * @throws DatabaseException
32
     */
33
    public static function execute(string $query, array $parameters = []): bool
34
    {
35
        return self::resolveQuery(__FUNCTION__, $query, $parameters);
36
    }
37
38
    /**
39
     * Raw query
40
     * @param string $query
41
     * @param array $parameters
42
     * @return array
43
     * @throws DatabaseException
44
     */
45
    public static function query(string $query, array $parameters = []): array
46
    {
47
        return self::resolveQuery(__FUNCTION__, $query, $parameters);
48
    }
49
50
    /**
51
     * Fetches table columns
52
     * @param string $query
53
     * @param array $parameters
54
     * @return array
55
     * @throws DatabaseException
56
     */
57
    public static function fetchColumns(string $query, array $parameters = []): array
58
    {
59
        return self::resolveQuery(__FUNCTION__, $query, $parameters);
60
    }
61
62
    /**
63
     * Gets the last query executed
64
     * @return string|null
65
     * @throws DatabaseException
66
     */
67
    public static function lastQuery(): ?string
68
    {
69
        return self::resolveQuery(__FUNCTION__);
70
    }
71
72
    /**
73
     * Get an array containing all the queries
74
     * run on a specified connection up to now.
75
     * @return array
76
     * @throws DatabaseException
77
     */
78
    public static function queryLog(): array
79
    {
80
        return self::resolveQuery(__FUNCTION__);
81
    }
82
83
    /**
84
     * Resolves the requested query
85
     * @param string $method
86
     * @param string $query
87
     * @param array $parameters
88
     * @return mixed
89
     * @throws DatabaseException
90
     */
91
    protected static function resolveQuery(string $method, string $query = '', array $parameters = [])
92
    {
93
        return self::getInstance()->getOrmClass()::$method($query, $parameters);
94
    }
95
}