npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-crud-api

v0.4.0

Published

JavaScript API for php-crud-api

Downloads

19

Readme

JS-CRUD-API

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

jca-filter

JCA-FILTER facilitates filters creation for JS-CRUD-API

Installation

  • via npm : npm i js-crud-api
import jscrudapi from 'js-crud-api';
const jca=jscrudapi('urlToApi.php');
jca.read('aTable',1);
  • via HTML
<script src="min.js"></script>
<script>
    const jca=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 listed here
  • 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 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

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']}); // AND
    jca.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>table2
    jca.read('aTable', {join:['table1','table2']});     // path : atable>table1>table2
    jca.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