PHP code example of jamielsharief / document-store

1. Go to this page and download the library: Download jamielsharief/document-store library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jamielsharief / document-store example snippets


use DocumentStore\Document;

$document = new Document();
$document->title = 'Patterns of Enterprise Application Architecture';
$document->author = 'Martin Fowler';
$document->type = 'hardcover';
$document->isbn = [
    '978-0321127426',
    '0321127420'
];

use DocumentStore\Document;

$document = new Document([
    'title' => 'Patterns of Enterprise Application Architecture',
    'author' => 'Martin Fowler',
    'type' => 'hardcover',
    'isbn' => [
        '978-0321127426',
        '0321127420'
    ]
]);

echo $document['title'];
$document['description'] = null;
unset($document['something']);

use DocumentStore\DocumentStore;
use DocumentStore\Document;

$store = new DocumentStore(storage_path('books'));

$document = new Document();
$document->title = 'Patterns of Enterprise Application Architecture';
$document->author = 'Martin Fowler';
$document->type = 'hardcover';
$document->isbn = [
    '978-0321127426',
    '0321127420'
];

$store->set('0321127420', $document);

$store->set('programming/0321127420', $document);

use DocumentStore\DocumentStore;
$store = new DocumentStore(storage_path('books'));

$document = $store->get('0321127420');

echo $document->title;

$document = $store->get('programming/0321127420');

use DocumentStore\DocumentStore;
$store = new DocumentStore(storage_path('books'));

$result = $store->has('0321127420');

$store->has('programming/0321127420');

use DocumentStore\DocumentStore;
$store = new DocumentStore(storage_path('books'));

$store->delete('0321127420');

$store->delete('programming/0321127420');

use DocumentStore\DocumentStore;
$store = new DocumentStore(storage_path('books'));

$list = $store->list(); // ['programming/0321127420']
$list = $store->list('programming'); // ['programming/0321127420']

$key = $document->key();

$document->toArray();

$document->toJson();
$document->toJson(['pretty' => true]);

use DocumentStore\DocumentStore;
$store = new DocumentStore(storage_path('books'));

$list = $store->search([
    'conditions' => ['author' => 'Dean Koontz'],
    'prefix' => 'fiction/horror', // optional
    'limit' => 10,  // limit the number of results
]);

$conditions = [
    'name' => 'Tony Stark' // searches string
    'emails' => '[email protected]', // searches data array
    'addresses.street' => '1000 malibu drive' // searches the street fields in addresses etc
];

$conditions = ['author' => 'Dean Koontz']
$conditions = ['author' => ['Steven King','Dean Koontz']

$conditions = ['author !=' => 'Dean Koontz']
$conditions = ['author !=' => ['Steven King','Dean Koontz']]

$conditions = ['age >' 21];
$conditions = ['age >=' 21];
$conditions = ['age <' 50];
$conditions = ['age <=' 50];

 $conditions = ['authors.name LIKE' =>'Tony%'];
 $conditions = ['author.name NOT LIKE' =>'%T_m%'];
 

$result = $store->find('first', [
    'conditions' => [
        'author' => ['Mark Minervini']
    ],
]);
/*
DocumentStore\Document Object
(
    [_id] => 5f730fd6ed12968109f89d0d
    [title] => Trade Like a Stock Market Wizard: How to Achieve Super Performance in Stocks in Any Market
    [author] => Mark Minervini
)
*/


$result = $store->find('all', [
    'conditions' => [
        'author' => ['Mark Minervini']
    ],
    'limit' => 2,
]);
/*
Array
(
    [0] => DocumentStore\Document Object
        (
            [_id] => 5f730fd6ed12968109f89d0d
            [title] => Trade Like a Stock Market Wizard: How to Achieve Super Performance in Stocks in Any Market
            [author] => Mark Minervini
        )
    [1] => DocumentStore\Document Object
        (
            [_id] => 5f730fde23b43a7800f7da25
            [title] => Mindset Secrets for Winning: How to Bring Personal Power to Everything You Do
            [author] => Mark Minervini
        )
)
*/

$count = $store->find('count', [
    'conditions' => [
        'author' => ['Mark Minervini']
    ],
]); // 3

use DocumentStore\DocumentDatabase;
use DocumentStore\Document;

$db = new DocumentDatabase(storage_path('books'));

$document = new Document();
$document->title = 'Patterns of Enterprise Application Architecture';
$document->author = 'Martin Fowler';
$document->type = 'hardcover';
$document->isbn = '0321127420';

$db->insert($document);

/*
DocumentStore\Document Object
(
    [_id] => 5f70951f2c7d2d8ba290f708
    [title] => Patterns of Enterprise Application Architecture
    [author] => Martin Fowler
    [type] => hardcover
    [isbn] => 0321127420
)
*/

$db->insert($document, [
    'prefix' => 'computing/programming'
]); // computing/programming/5f70951f2c7d2d8ba290f708

$db->insertMany([$document]);

$db->update($document);

$db->updateMany([$document]);