Download the PHP package netflex/database without Composer
On this page you can find all versions of the php package netflex/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package database
Netflex Database Driver for Laravel
This package provides a database driver for Laravel that enables you to use the Netflex API as a database backend for your Laravel application.
This package supports Laravel 8 through 10, and PHP 7.4 through 8.2.
Table of contents
- Motivation / Why?
- Installation
- Usage
- Configuration
- Eloquent
- Reference Model
- Models
- Caveats
- Migrations
- Netflex specific functionality
- Caching
- Automatically respecting the publishing status of an entry
- Refresh data from API on save
- Automatically setting name of entries
- Limitations
- Todo
- License
Motivation / Why?
Laravel provides a powerful database abstraction layer that allows you to use a variety of different database backends.
Most first and third party packages in the Laravel ecosystem assumes that you are using a relational database backend.
This package enables you to use the Netflex API as a database backend for your Laravel application, bridging the gap between the Netflex API and Laravel.
This enables you to use most of Laravels functionality out of the box, while still using the Netflex API as your backend.
Installation
You can install the package via composer:
Usage
Configuration
Add the following to your config/database.php file:
Note that the adapter property is required if you want to be able to perform "write" operations, and must be set to a valid adapter name. The following adapters are currently supported:
entry(Full support)customer(Write support, schema manipulation not supported due to API limitations)page(Read-only support)read-only(also aliased asdefaultfor fallback purposes)
If no adapter is specified, the connection will only work as a read-only connection, and you won't be able to interrogate your connections Schema or perform any write operations.
Note that by using the entry adapter, your models $prefix property will be prepended with entry_ to match the Netflex index naming convention.
You may also provide a custom adapter class. It needs to implement the Netflex\Database\DBAL\Contracts\DatabaseAdapter interface.
The adapter is responsible for translating betweeen the database layer of Laravel and the Netflex API.
Advanced configuration
Using different API connections
If you have multiple API connections configured, you can specify which one to use by setting the connection property on the connection configuration. (See netflex/api for reference).
Eloquent
Refrence Model
This package provides a reference model that you can use as a base for your models. This is recommended for most use cases, as it provides a number of useful features.
Models
To use the Netflex API as a database backend for your Eloquent models, all you have to do is register a database connection that use the netflex driver.
If you have configured aliases for your Netflex structures, you can skip name $table property and let Eloquent resolve the index name for you based on the models alias.
If creating structures through Laravel migrations and using the entry adapter, we will automatically add a table alias for you. This alias follows the convention of the pluralized model name in snake_case.
Example:
In the following example, a default database connection is configured with the name structures to use the netflex driver, and the entry adapter.
config/database.php
Laravel will infer the table name from the model name, and use the entry_ prefix configured on the 'netflex' driver backed connection.
This means that the search queries will be mapped to the entry_articles index.
If not using aliases, you can use the following syntax:
If you have multiple database connections, and the default connection is not configured to use the netflex driver, you can specify the connection to use by setting the $connection property on your model.
Caveats
Since the Netflex API uses the field names created and updated for it's default timestamps, remember to configure that in your model, since Eloquent assumes created_at and updated_at by default.
Migrations
Migrations are supported for the entry adapter, and will automatically create or alter the structure in Netflex.
Reserved fields in the Netflex API are automatically handled, and will not be added or altered. This allows you to re-use the same migrations for both Netflex and relational databases.
Unique contraints and cascades are not supported. You can have them in your migration, but they will be ignored.
You create and manage migrations as you normally would through Artisan.
If no types are specified, the following types will be used:
- text (string)
- textarea (bigText, text, bigInt etc)
- integer (int)
- float (float, decimal)
- checkbox (boolean)
- json (json)
Default values are supported. Here you may also use the special syntax for Netflex to automatically add certain values, like datetimes and UUID's etc. See Netflex documentation for more information.
Assuming you have configured a default database connection to use the netflex driver with the entry adapter:
Netflex specific functionality
If you have previously used the Model implmentation from the Netflex SDK, some functionality was provided out of the box, that isn't compatible with Eloquent models directly.
This packages provides some traits that you can apply to your models to bring back this functionality.
All of these features are provided out of the box (except caching) if you use the Netflex\Database\Eloquent\Model as your base model.
Caching
This driver does not deal with caching, as that is a concern that should be handled by the application. The recommended substitute for automatic caching is to use the a tagged cache driver and installing a third party package that deals with caching Eloquent models.
Recommended packages:
Automatically respecting the publishing status of an entry
If you want to automatically respect the publishing status of an entry, you can apply the Netflex\Database\Concerns\Publishable trait to your model.
Refresh data from API on save
When inserting or updating an entry, some of it's data might get modified by the API, such as the id or url property, etc.
Laravel does not automatically refresh the model after saving (for performance reasons), so you might end up with stale data.
If you want to automatically refresh the model after saving, you can apply the Netflex\Database\Concerns\RefreshesOnSave trait to your model.
Automatically setting name of entries
If you attempt to insert an entry without the name attribute set, the API will throw an error.
In the Netflex SDK, this was automatically handled by the model, but this isn't consistent with Eloquent models.
You can add this functionality back by applying the Netflex\Database\Concerns\GeneratesName trait to your model.
This will automatically generate a UUID based name for the entry, unless a name is provided.
Limitations
This package is tested on PHP >7.4.and PHP 8.0 through 8.2.
Currently the internal virtual PDO implementation is implemented as a separate package (netflex/dbal). This is because the internal type signatures of PDO changed between PHP 7.4 and 8.0, and we need to support both versions.
At a later stage, when we drop support for PHP 7.4, we will move the PDO stubs into this package's codebase.
License
The MIT License (MIT). Please see License File for more information.
Copyright © 2023 Apility AS
All versions of database with dependencies
illuminate/support Version ^10.0
illuminate/database Version ^10.0
netflex/api Version ^4.0
netflex/dbal Version ^3.0
netflex/query-builder Version ^4.0