Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fatfingers23/replit-database-client
Simple Php Replit Database Client
https://github.com/fatfingers23/replit-database-client
Last synced: 10 days ago
JSON representation
Simple Php Replit Database Client
- Host: GitHub
- URL: https://github.com/fatfingers23/replit-database-client
- Owner: fatfingers23
- License: mit
- Created: 2022-04-26T05:04:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-05-02T18:28:59.000Z (over 2 years ago)
- Last Synced: 2024-05-02T02:43:31.526Z (7 months ago)
- Language: PHP
- Size: 1.68 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: FUNDING.YML
- License: LICENSE
Awesome Lists containing this project
README
Repl.it PHP Database Client
============Simple Repl.it database client in PHP. Loosely based off of the [replit/database-node](https://github.com/replit/database-node).
[![License](http://poser.pugx.org/fatfingers23/replit-database-client/license)](https://packagist.org/packages/fatfingers23/replit-database-client)
[![Run on Repl.it](https://repl.it/badge/github/fatfingers23/Replit-Database-Client)](https://repl.it/github/fatfingers23/Replit-Database-Client)Requirements
------------* PHP >= 8.0;
* Composer.Installation
============`composer require fatfingers23/replit-database-client`
## Get started
```php
set('key', 'value');
$key = $client->get('key');
echo $key;
```
## Docs
Client
> ### `class DatabaseClient(String url?)`
Ability to pass a custom url**Native Functions**
> `set(string $key, array|string $value): void`
Sets a key with a string value
```php
set('key', 'value');
```Sets a key with an array value
```php
set('key', ['greeting' => 'Hello World!']);
```> `get(string $key): array|string|null`
Gets a key with a string value
```php
get('key');
echo $key;
```Gets a key with an array value
```php
get('key');
var_dump($key);
echo $key['greeting'];
```> `delete(string $key): void`
Deletes an entry in the database by its key
```php
delete('key');
```> `getPrefixKeys(string $prefix): array`
* Returns an array of keys that start with the prefix
* If no prefix is given returns all the keys in the database
* Returns an empty array if it finds no keys
```php
set('poet.1', 'John Keats');
$client->set('poet.2', 'Emily Dickinson');
$poetKeys = $client->getPrefixKeys('poet');#var_export($poetKeys) result below
array (
0 => 'poet.1',
1 => 'poet.2',
)
```**Extended Functions**
> `getPrefix(string $prefix): ?array`
* Returns an array of all the values to a prefix
* If no prefix is given returns the whole database
* Returns null if no prefixs are found
```php
set('poet.1', 'John Keats');
$client->set('poet.2', 'Emily Dickinson');
$poets = $client->getPrefix('poet');#var_export($poets) result below
array (
'poet.1' => 'John Keats',
'poet.2' => 'Emily Dickinson',
)
```> `deleteByPrefix(string $prefix = '')`
* Deletes a series of keys by their prefix
* Careful if no prefix is given, this function will delete the entire database
```php
deleteByPrefix('poet');
```## Tests
```sh
composer test
```
or can just click run if this is open in a Repl.itContributing
============1. Fork it.
2. Create your feature branch (git checkout -b my-new-feature).
3. Make your changes.
4. Run the tests, adding new ones for your own code if necessary (phpunit).
5. Commit your changes (git commit -am 'Added some feature').
6. Push to the branch (git push origin my-new-feature).
7. Create new pull request.