19.2. Access To PostgreSQL Tables

19.2.1. Create Dataset

example:

19.2.2. Read Dataset

example:

19.2.3. Update Dataset

example:

19.2.4. Delete Dataset

example:

19.2.5. Fine Grained Pre-check Function

If the PostgreSQL function api_pre_check(IN TEXT,IN TEXT,IN TEXT,IN "char",IN TEXT,IN TEXT) exists, server will execute this function for every API request. Server will abandon that request if this function returns false or raises execption. (Avoid raising exceptions because PostgreSQL is often configured to log exceptions, which consumes disk space.)

Function api_pre_check() parameters are described as follows:

  1. user id

  2. target table name

  3. company code

  4. c, r, u, or d

  5. condition

    If the API request is sent in as this:

    curl -v -H "Content-Type:Application/json" -H 'Authorization:abHEi47obYMiCi193xjEiWIFpOouNmkd' -H 'X-Auth-Database:dev5' -d '{"table":"t52","company":"1","query":[[["f0","1"],["f1",4]],[["f4",880],["f5",0]]]}' https://34.terarows.com/fastcgi/api/u
    					

    , the argument condition is passed by server with the value of key "query": [[["f0","1"],["f1",4]],[["f4",880],["f5",0]]]

These arguments are automatically provided by server when it executes the API requests.

api_pre_check() example:

CREATE FUNCTION api_pre_check(user_id TEXT,table_name TEXT,company TEXT,crud "char",query TEXT) RETURNS BOOLEAN AS $$
BEGIN
	IF crud IN ('u','d') THEN 
		RETURN
			EXISTS (SELECT 1 FROM t43 WHERE f1=user_id AND f8)
			AND EXISTS (SELECT 1 FROM t52 WHERE f0=company AND AGE(f2) < INTERVAL '1 month');
	END IF;
	RETURN TRUE;
END $$ LANGUAGE PLPGSQL STABLE;