Passed
Push — master ( 4ac107...bec696 )
by Aleksandar
72:47
created

select()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2021 Aleksandar Panic
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace ArekX\PQL\Sql;
19
20
use ArekX\PQL\Contracts\StructuredQuery;
21
use ArekX\PQL\Sql\Query\Delete;
22
use ArekX\PQL\Sql\Query\Insert;
23
use ArekX\PQL\Sql\Query\Select;
24
25
if (!function_exists('\ArekX\PQL\Sql\select')) {
26
    /**
27
     * Create a SELECT query.
28
     *
29
     * @param null|array|StructuredQuery $columns Columns to be selected
30
     * @return Select
31
     * @see Select
32
     */
33
    function select($columns = null): Select
34
    {
35 1
        return Select::create()->columns($columns);
36
    }
37
}
38
39
if (!function_exists('\ArekX\PQL\Sql\insert')) {
40
    /**
41
     * Create a INSERT query
42
     *
43
     * @param string|StructuredQuery $into Where to insert data to.
44
     * @param array $data Associative array of data to be inserted.
45
     * @return Insert
46
     */
47
    function insert($into, $data = null)
48
    {
49 1
        $query = Insert::create()->into($into);
50
51 1
        if ($data !== null) {
52 1
            $query->data($data);
53
        }
54
55 1
        return $query;
56
    }
57
}
58
59
if (!function_exists('\ArekX\PQL\Sql\delete')) {
60
    /**
61
     * Creates a DELETE query
62
     *
63
     * @param string|StructuredQuery $from From where to delete
64
     * @param null|array|StructuredQuery $condition Filter for deletion
65
     * @return Delete
66
     */
67
    function delete($from, $condition = null)
68
    {
69 1
        return Delete::create()->from($from)->where($condition);
70
    }
71
}