Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JavaScript client library for the API of PHP-CRUD-API

License

NotificationsYou must be signed in to change notification settings

thipages/js-crud-api

Repository files navigation

JavaScript client library for the API ofPHP-CRUD-API

jca-filter

JCA-FILTERfacilitates filters creation for JS-CRUD-API

Installation

  • 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>

Promise-based

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)

API

JS-CRUD-API accesses PHP-CRUD-API with the following functions

  • CRUD functions
CRUD functionsexamples
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

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']});

Limitations

  • Endpoints not (yet) implemented

    • /openapi
    • /geojson
    • /columns
    • /status/ping
  • Only DBAuth is implemented (not basic and JWT authentications)

Tests

  • PHP-CRUD-API v2.14.25
  • SQLite v3.43.2

About

JavaScript client library for the API of PHP-CRUD-API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp