Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
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
sinan
laravel-mongodb
Commits
fd651f58
Unverified
Commit
fd651f58
authored
Feb 18, 2020
by
Giacomo Fabbian
Committed by
GitHub
Feb 18, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into pr_1534_1
parents
f9006bd2
3f5b1dc5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
11 deletions
+36
-11
Model.php
src/Jenssegers/Mongodb/Eloquent/Model.php
+1
-0
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+5
-3
Builder.php
src/Jenssegers/Mongodb/Schema/Builder.php
+26
-8
SchemaTest.php
tests/SchemaTest.php
+4
-0
No files found.
src/Jenssegers/Mongodb/Eloquent/Model.php
View file @
fd651f58
...
...
@@ -2,6 +2,7 @@
namespace
Jenssegers\Mongodb\Eloquent
;
use
Illuminate\Support\Carbon
;
use
DateTime
;
use
Illuminate\Contracts\Queue\QueueableCollection
;
use
Illuminate\Contracts\Queue\QueueableEntity
;
...
...
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
fd651f58
...
...
@@ -234,16 +234,18 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
}
/**
* @inheritdoc
* Indicate that the collection needs to be created.
* @param array $options
* @return void
*/
public
function
create
()
public
function
create
(
$options
=
[]
)
{
$collection
=
$this
->
collection
->
getCollectionName
();
$db
=
$this
->
connection
->
getMongoDB
();
// Ensure the collection is created.
$db
->
createCollection
(
$collection
);
$db
->
createCollection
(
$collection
,
$options
);
}
/**
...
...
src/Jenssegers/Mongodb/Schema/Builder.php
View file @
fd651f58
...
...
@@ -33,20 +33,20 @@ class Builder extends \Illuminate\Database\Schema\Builder
/**
* Determine if the given collection exists.
* @param string $
collection
* @param string $
name
* @return bool
*/
public
function
hasCollection
(
$
collection
)
public
function
hasCollection
(
$
name
)
{
$db
=
$this
->
connection
->
getMongoDB
();
foreach
(
$db
->
listCollections
()
as
$collectionFromMongo
)
{
if
(
$collectionFromMongo
->
getName
()
==
$collection
)
{
return
true
;
}
}
$collections
=
iterator_to_array
(
$db
->
listCollections
([
'filter'
=>
[
'name'
=>
$name
,
],
]),
false
);
return
false
;
return
count
(
$collections
)
?
true
:
false
;
}
/**
...
...
@@ -134,6 +134,24 @@ class Builder extends \Illuminate\Database\Schema\Builder
return
new
Blueprint
(
$this
->
connection
,
$collection
);
}
/**
* Get collection.
* @param string $name
* @return bool|\MongoDB\Model\CollectionInfo
*/
public
function
getCollection
(
$name
)
{
$db
=
$this
->
connection
->
getMongoDB
();
$collections
=
iterator_to_array
(
$db
->
listCollections
([
'filter'
=>
[
'name'
=>
$name
,
],
]),
false
);
return
count
(
$collections
)
?
current
(
$collections
)
:
false
;
}
/**
* Get all of the collections names for the database.
* @return array
...
...
tests/SchemaTest.php
View file @
fd651f58
...
...
@@ -34,6 +34,10 @@ class SchemaTest extends TestCase
Schema
::
create
(
'newcollection_two'
,
null
,
[
'capped'
=>
true
,
'size'
=>
1024
]);
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection_two'
));
$this
->
assertTrue
(
Schema
::
hasTable
(
'newcollection_two'
));
$collection
=
Schema
::
getCollection
(
'newcollection_two'
);
$this
->
assertTrue
(
$collection
[
'options'
][
'capped'
]);
$this
->
assertEquals
(
1024
,
$collection
[
'options'
][
'size'
]);
}
public
function
testDrop
()
:
void
...
...
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