Download the PHP package jamielsharief/document-store without Composer
On this page you can find all versions of the php package jamielsharief/document-store. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jamielsharief/document-store
More information about jamielsharief/document-store
Files in jamielsharief/document-store
Informations about the package document-store
DocumentStore
DocumentStore is a Key-Value Store (KVS) that stores data in JSON documents, giving you a productive way to work with simple or nested data and allows for felxible and dynamic schema. Data can easily be synced across multiple servers. This provides a consistent interface for working with JSON data as a no SQL database.
Creating a Document
Create a Document and add any data you like, it can be nested include arrays
You can also create a Document from an array
The Document object can also be accessed as an array
Set
To add a Document to the DocumentStore
You can also group Documents using a prefixes (as many levels) which organizes the Documents into folders.
Get
To get a Document from the DocumentStore
To get a Document with a prefix
Has
To check a Document exists
To check a Document with a prefix
Delete
To delete a Document from the DocumentStore
To delete a Document with a prefix
List
To list Documents in the DocumentStore
Document
Key
If you are working a Document that was stored in the DocumentStore, you can use the key method
to get the key that was used. This is handy for when working with search results from find first or find all.
To Array
To convert the Document into an array
To Json
To convert the Document into a JSON string
Searching
You can also search Documents in the DocumentStore, this is a file based searched . So if you have 100,000s of Documents in a prefix or regularly perform large amounts of searches and speed is an issue, maybe an indexing software like Elasticsearch or Solr might be worth looking at.
Keys
To get a list a keys that match a set of conditions (see below). There are also finders, which are detailed after conditions.
The following options can be passed
- prefix: to search a given prefix e.g. computers/development
- conditions: an array of conditions
- limit: the maximum number of results to find
- offset: the offset from which matching record to find. This is handy when you want to paginate results using limit
Fields
You can search different fields using the dot notation, and you can searched nested data as well.
Lets say you have this data
Here are some examples how to search the the different levels of fields;
Conditions
Here are some examples on the different search conditions
Equals
You can check single or multiple values (IN)
Not Equals
You can check single or multiple values (NOT IN)
Arithmetic
To check field values, such as greater, less than etc.
Like
You can use SQL LIKE and NOT LIKES using the wildcard % for any chars or _ for just one character, this is a case insensitive search.
Finders
You can use the key method on any document found using first or all to find what key was used to save that Document.
First
To find the first Document that matches a set of conditions
All
To find all Documents that match a set of conditions
Count
If you only want the count then use this but if you want the count and records, count the results manually from search or the all finder, to prevent repetitive and pointless searching on the hard drive.
To find a count Documents that match a set of conditions
Document Database
There is a DocumentDatabase adapter which uses the DocumentStore as the backend, but makes it work similar to a database, such as generating keys, saving multiple records etc.
Insert
Insert first generates a unique ID, adds an _id field to the Document, then adds this to the DocumentStore using the ID as the key.
You can also insert into a particular path
There is also an insertMany method
Update
When you are working with Documents that have already been saved in the DocumentDatabase, and have an _id field you can save any changes using the update method.
There is also an updateMany method