- Notifications
You must be signed in to change notification settings - Fork4
JavaScript client library for the API of PHP-CRUD-API
License
thipages/js-crud-api
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
JavaScript client library for the API ofPHP-CRUD-API
JCA-FILTERfacilitates filters creation for JS-CRUD-API
- via npm :npm i js-crud-api
importjscrudapifrom'js-crud-api';constjca=jscrudapi('urlToApi.php');jca.read('aTable',1);
- via HTML
<scriptsrc="min.js"></script><script>constjca=jscrudapi('urlToApi.php');jca.list('aTable');</script>
All functions (see API) are promise-based
jca.create('atable',{field:'value'}).then(result=>console.log(result)).catch(error=>console.log(error));
Errors
- PHP-CRUD-API error codes and related messages are listedhere
- An generic javascript related error code has been added : -1 (eg fetch network error)
JS-CRUD-API accesses PHP-CRUD-API with the following functions
- CRUD functions
| CRUD functions | examples |
|---|---|
| read (table,ids,conditions={}) | read('atable', 1) |
read('atable', '1,2') | |
read('atable', [1,2]) | |
read('atable', 1,{join:'anotherTable'}) | |
| list (table, conditions={}) | list('atable') |
list('atable', {filter:'id,eq,1'}) | |
list('atable', {filter:['id,eq,1','id,eq,2']}) | |
| other conditions here | |
| create (table,data) | create('atable', {field:'value'}) |
create('atable', [{field:'value1'},{field:'value2'}]) | |
| update (table,idOrList,data) | update('atable',1 {field:'newValue'}) |
update('atable','1,2' [{field:'newValue1'},{field:'newValue2'}]) | |
update('atable',[1,2] [{field1:'newValue1'},{field2:'newValue2'}]) | |
| delete (table,idOrList) | delete('atable',1) |
delete('atable','1,2') | |
delete('atable',[1,2]) |
Authentication functions (see documentation)
register(username,password)login (username,password)password (username,password,newPassowrd)logout()me()
Conditions are stored as object properties, values as (array of) string/number
FILTERING (documentation)
jca.read('aTable',{filter:'field,modifier,value'});jca.read('aTable',{filter:['field1,modifier1,value1','field2,modifier2,value2']});// ANDjca.read('aTable',{filter:'field1,modifier1,value1',filter1:'field2,modifier2,value2'});// OR
Modifiers
- cs(contain string), sw(start with), ew(end with), eq(equal), lt(lower than), le(lower or equal), ge(greater or equal), gt(greater than), bt(between), in, is(is null)
- filters can be negated by prepending a "n" character (eg "eq" becomes "neq")
JOINING (documentation)
jca.read('aTable',{join:'table1'});jca.read('aTable',{join:'table1,table2'});// path : atable>table1>table2jca.read('aTable',{join:['table1','table2']});// path : atable>table1>table2jca.read('aTable',{join:[['table1'],['table2']]});// paths: atable>table1 and atable>table2
SIZING
jca.read('aTable',{size:10});
PAGINATING
jca.read('aTable',{page:'1,50'});jca.read('aTable',{page:1});
SELECTING COLUMN
jca.read('aTable',{include:'field'});jca.read('aTable',{include:['field1,field2']});jca.read('aTable',{exclude:['field1']});
ORDERING
jca.read('aTable',{order:'field,desc'});jca.read('aTable',{order:['field1,desc','field2']});
Endpoints not (yet) implemented
- /openapi
- /geojson
- /columns
- /status/ping
Only DBAuth is implemented (not basic and JWT authentications)
- PHP-CRUD-API v2.14.25
- SQLite v3.43.2
About
JavaScript client library for the API of PHP-CRUD-API
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.