Skip to content

Commit

Permalink
Improve mongo implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kekefreedog committed May 19, 2024
1 parent 1497d8f commit 521c7d5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Core/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public function setContent(/* string|array|resource|StreamInterface */$body = ""
* Push Content on Api Response
*
* @param string $where Where put content in content
* @param string|bool|array|int|null $content to push
* @param mixed $content to push
* @return self
*/
public function pushContent(string $where = "", string|bool|array|int|null $content = null):self {
public function pushContent(string $where = "", mixed $content = null):self {

# Check where
if(!$where)
Expand Down
24 changes: 23 additions & 1 deletion src/Driver/Model/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,33 @@ public function run():array {
$validator = Mangodb::convertToMongoSchema($this->arguments["schema"]);

# Get result
$result[] = $this->mongodb->insertToCollection($this->arguments["collection"], $data, $this->arguments["database"], true, $validator);
$currentResult = $this->mongodb->insertToCollection($this->arguments["collection"], $data, $this->arguments["database"], true, $validator);

$result[] = [
"MongoDB\InsertOneResult" => $currentResult,
"_id" => $currentResult->getInsertedId(),
"id" => (string) $currentResult->getInsertedId(),
"count" => $currentResult->getInsertedCount(),
"acknowledged" => $currentResult->isAcknowledged(),
];

}

}

}else
# Find One by Id
if($this->id !== null && $this->id){

# Prepare $this->findOptions
$this->findOptions = [
"filters" => [
"_id" => $this->id,
]
];

# Find value
$result = $this->mongodb->findOne($this->arguments["collection"], $this->arguments["database"], $this->findOptions);

}else{

Expand Down
9 changes: 9 additions & 0 deletions src/Front/Library/Loader/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,15 @@ export default class Page {
// Stop function
return options;

// Declare new title
let titleNew = options.name;

// Check titleNew
if(titleNew)

// Set title
document.title = titleNew;

// Return options
return options;

Expand Down
51 changes: 51 additions & 0 deletions src/Library/Database/Driver/Mangodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,57 @@ public function find(string $collectionName, string $database, array $options =

}

/**
* Find One
*
* Find value
*
* @param string $collectionName
* @param string $database
* @param array $options = [
* "filters":array
* ]
*/
public function findOne(string $collectionName, string $database, array $options = []):array|null {

# Set result
$result = null;

# Check input
if(!$collectionName || !$database)

# Return result
return $result;

# Connect to database
$database = $this->client->$database;

# Connect to the collection
$collection = $database->$collectionName;

# Set filters
$filters = isset($options["filters"]) && is_array($options["filters"])
? $options["filters"]
: []
;

# Iteration filters
foreach($filters as $key => &$filter)

# Check if _id
if($key === "_id")

# Convert string
$filter = new ObjectId($filter);

# Last result
$result = [$collection->findOne($filters, $options)];

# Return result
return $result === null ? [] : $result;

}

/**
* Find Last One
*
Expand Down

0 comments on commit 521c7d5

Please sign in to comment.