Download the PHP package dwgebler/doclite without Composer
On this page you can find all versions of the php package dwgebler/doclite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package doclite
DocLite
A powerful PHP NoSQL document store built on top of SQLite.
Table of contents
- About DocLite
- Why DocLite?
- Getting Started
- The Database
- Creating a memory database
- Creating a file database
- Error Handling & Logging
- Import and export data
- Importing Data
- Exporting data
- Advanced options
- Get DocLite version
- Optimize database
- Set synchronization mode
- Set rollback journal mode
- Collections
- About Collections
- Obtain a collection
- Create a document
- Save a document
- Retrieve a document
- Map a document to a custom class
- Delete a document
- Query a collection
- Find single document by values
- Find all matching documents by values
- Find all documents in collection
- Advanced queries
- Query operators
- Join collections
- Caching results
- Index a collection
- Unique indexes
- Delete a collection
- Collection transactions
- Full text search
- Documents
- About Documents
- Getting and setting document data
- Mapping document fields to objects
- Document Unique Id
- Saving a document
- Deleting a document
- Document validation
- Other info
- Symfony integration
- Licensing
- Bugs, issues
- Contact the author
About DocLite
DocLite is a powerful NoSQL document store for PHP built on top of SQLite. It uses the PHP PDO SQLite library to access a SQLite database and automatically manage documents organized in to named collections, which are stored as JSON.
DocLite takes advantage of the SQLite JSON1 extension (this is usually bundled in to the libsqlite included with your PHP distribution, so you probably already have it) to store, parse, index and query JSON documents - giving you the power and flexibility of a fully transactional and ACID compliant NoSQL solution, yet contained within the local file system. No need for more complex systems like Mongo, CouchDB or Elasticsearch when your requirements are slim. No need for any external dependencies, just PHP with PDO SQLite enabled.
DocLite provides a simple, intuitive, flexible and powerful PHP library that you can learn, install and start using in minutes.
Why DocLite?
DocLite lends itself well to a variety of use cases, including but not limited to:
-
Agile development and rapid prototyping while your requirements are evolving.
-
Powerful, self-contained NoSQL database for small to medium websites or applications, such as blogs, business website, CMS, CRM or forums.
-
A fast and reliable cache for data retrieved from remote databases, APIs or servers. Process your data in to documents, save in DocLite and easily query and filter your data as needed.
-
Robust, performant, ACID compliant replacement for weaker, slower, flat-file data stores utilizing JSON, XML or YAML.
-
Application database for web apps installed and run on a local environment.
-
Database for microservices and middleware.
- Fast in-memory database for data processing or machine learning algorithms.
Broadly speaking, DocLite is suitable for the same uses cases as the underlying SQLite engine it is built on, but where you desire a NoSQL solution.
Getting Started
System requirements
- PHP 7.4 or above - With PDO SQLite enabled, built against libsqlite ≥ 3.18.0 with JSON1 extension. (on most systems, if you're running PHP 7.4 you probably already meet the second requirement)Installation
Install with [Composer](https://getcomposer.org/) `composer require dwgebler/doclite`Usage Overview
DocLite provides both a `FileDatabase` and `MemoryDatabase` implementation. To create or open an existing database, simply create a `Database` object, specifying the file path if using a `FileDatabase`. If your `FileDatabase` does not exist, it will be created (ensure your script has the appropriate write permissions). This will include creating any parent directories as required. If you specify an existing directory without a filename, a default filename `data.db` will be used. Once you have opened a database, you can obtain a document `Collection` which will be automatically created if it does not exist. The `Collection` object can then be used to retrieve, create and manipulate documents. In the example above, `$user` is an instance of a DocLite `Document`, but you can also hydrate objects of your own custom classes from a collection. To learn more about the `Collection` object including how to query a document store, please read the full documentation below.The Database
DocLite is built on top of SQLite 3 and supports two types of database; file and memory.
The corresponding classes are FileDatabase
and MemoryDatabase
.
Creating a memory database
MemoryDatabase
is stored in volatile memory and is therefore ephemeral for the lifetime
of your application scripts. Its constructor takes optional parameters:
- a boolean flag indicating whether to enable full text search features (defaults to
false
) - this feature requires SQLite to have been compiled with the FTS5 extension. - an integer representing the maximum connection timeout in seconds (defaults to
1
) which is how long the connection should wait if the underlying SQLite database is locked. - A PSR-3 compatible logger instance (defaults to
null
).
php use Gebler\Doclite\MemoryDatabase;
$db = new MemoryDatabase();
// With full text search enabled and a 2-second connection timeout $logger = new \Monolog\Logger('my-logger'); $db = new MemoryDatabase(true, 2, $logger); yaml username: adamjones first_name: Adam last_name: Jones password: "$2y$10$LRS.0xUCJjWSmQuWMMRsuurZ0OGlU.NH7KYXsipzkfUa0YREEarj2" address: street: 123 Fake Street area: Testville county: Testshire postcode: TE1 3ST roles:
- USER
- EDITOR
telephone: "+441234567890"
registered: true
active: true
lastLogin: "2021-02-13T10:34:40+00:00"
email: [email protected]
api_access:
"/v1/pages/":
- POST
- GET "/v1/contributors/":
- GET yaml __id: b83e319a-7887-11eb-8deb-b9e03d2e720d username: daniel_johnson1 active: false roles:
- CONTRIBUTOR
-
AUTHOR telephone: "+441254220959364" password: "$2y$10$y8P2Cjph1F.iIc.s2j9aM.GW9qy8aOMeEfzDulQox465mgBJF.pPG" person: firstName: Daniel lastName: Johnson address: house: '123' street: Test Road city: Testville Country: Testshire postcode: "TE1 3ST" dateOfBirth: '1980-03-23T00:00:00+00:00' identityVerified: true yaml app.filedatabase: class: Gebler\Doclite\FileDatabase arguments: $path: "../var/data/app.db" $readOnly: false app.memorydatabase: class: Gebler\Doclite\MemoryDatabase
Gebler\Doclite\DatabaseInterface: '@app.filedatabase' Gebler\Doclite\DatabaseInterface $memoryDb: '@app.memorydatabase'
You can now typehint a DatabaseInterface
like any other service, using the
alias $memoryDb
as the parameter name if you'd like a MemoryDatabase
.
Licensing
DocLite is available under the MIT license as open source software.
If you use DocLite and find it useful, I am very grateful for any support towards its future development.
Bugs, issues
Please raise an issue on the project GitHub if you encounter any problems. I am always interested in improving the software.
Contact the author
You can email me on [email protected]
All versions of doclite with dependencies
ext-json Version *
ext-pdo Version *
ext-pdo_sqlite Version *
swaggest/json-schema Version ^0.12.31
symfony/property-access Version ^5.2 || ^6.0 || ^7.0
symfony/property-info Version ^5.2 || ^6.0 || ^7.0
symfony/serializer Version ^5.2 || ^6.0 || ^7.0
symfony/uid Version ^5.3 || ^6.0 || ^7.0
symfony/yaml Version ^5.2 || ^6.0 || ^7.0
psr/log Version ^1.1 || ^3.0