Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
684bbebb
Commit
684bbebb
authored
Aug 21, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring the database layer.
parent
a940fc48
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
72 deletions
+26
-72
application.php
laravel/config/application.php
+1
-1
compiler.php
laravel/db/compiler.php
+13
-69
query.php
laravel/db/query.php
+12
-2
No files found.
laravel/config/application.php
View file @
684bbebb
...
...
@@ -11,7 +11,7 @@ return array(
|
*/
'url'
=>
'http://localhost
/laravel/public
'
,
'url'
=>
'http://localhost'
,
/*
|--------------------------------------------------------------------------
...
...
laravel/db/compiler.php
View file @
684bbebb
...
...
@@ -10,80 +10,24 @@ class Compiler {
*/
public
function
select
(
Query
$query
)
{
foreach
(
array
(
'add_select'
,
'add_from'
,
'add_where'
,
'add_order'
,
'add_limit'
,
'add_offset'
)
as
$builder
)
$sql
=
$query
->
select
.
' '
.
$query
->
from
.
' '
.
$query
->
where
;
if
(
!
is_null
(
$query
->
order
))
{
$sql
[]
=
$this
->
$builder
(
$query
)
;
$sql
.=
' '
.
$query
->
order
;
}
foreach
(
$sql
as
$key
=>
$value
)
{
if
(
is_null
(
$value
)
or
$value
===
''
)
unset
(
$sql
[
$key
]);
}
return
implode
(
' '
,
$sql
);
}
/**
* Get the SELECT clause from the Query instance.
*
* @param Query $query
* @return string
*/
protected
function
add_select
(
Query
$query
)
{
return
$query
->
select
;
}
/**
* Get the FROM clause from the Query instance.
*
* @param Query $query
* @return string
*/
protected
function
add_from
(
Query
$query
)
{
return
$query
->
from
;
}
/**
* Get the WHERE clause from the Query instance.
*
* @param Query $query
* @return string
*/
protected
function
add_where
(
Query
$query
)
{
return
$query
->
where
;
}
/**
* Get the ORDER BY clause from the Query instance.
*
* @param Query $query
* @return string
*/
protected
function
add_order
(
Query
$query
)
{
if
(
count
(
$query
->
orderings
)
>
0
)
return
'ORDER BY'
.
implode
(
', '
,
$query
->
orderings
);
}
if
(
!
is_null
(
$query
->
limit
))
{
$sql
.=
' '
.
$query
->
limit
;
}
/**
* Get the LIMIT clause from the Query instance.
*
* @param Query $query
* @return string
*/
protected
function
add_limit
(
Query
$query
)
{
if
(
!
is_null
(
$query
->
limit
))
return
'LIMIT '
.
$query
->
limit
;
}
if
(
!
is_null
(
$query
->
offset
))
{
$sql
.=
' '
.
$query
->
offset
;
}
/**
* Get the OFFSET clause from the Query instance.
*
* @param Query $query
* @return string
*/
protected
function
add_offset
(
Query
$query
)
{
if
(
!
is_null
(
$query
->
offset
))
return
'OFFSET '
.
$query
->
offset
;
return
$sql
;
}
/**
...
...
laravel/db/query.php
View file @
684bbebb
...
...
@@ -55,6 +55,13 @@ class Query {
*/
public
$where
=
'WHERE 1 = 1'
;
/**
* The ORDER BY clause.
*
* @var string
*/
public
$order
;
/**
* The ORDER BY columns.
*
...
...
@@ -417,6 +424,9 @@ class Query {
public
function
order_by
(
$column
,
$direction
=
'asc'
)
{
$this
->
orderings
[]
=
$this
->
wrap
(
$column
)
.
' '
.
strtoupper
(
$direction
);
$this
->
order
=
'ORDER BY '
.
implode
(
', '
,
$this
->
orderings
);
return
$this
;
}
...
...
@@ -428,7 +438,7 @@ class Query {
*/
public
function
skip
(
$value
)
{
$this
->
offset
=
$value
;
$this
->
offset
=
'OFFSET '
.
$value
;
return
$this
;
}
...
...
@@ -440,7 +450,7 @@ class Query {
*/
public
function
take
(
$value
)
{
$this
->
limit
=
$value
;
$this
->
limit
=
'LIMIT '
.
$value
;
return
$this
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment