PostgreSQL native library for Tarantool programming language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

json.lua 615B

12345678910111213141516171819202122
  1. ------------------------------
  2. -- tarantool_psql json handler -
  3. ------------------------------
  4. local __pcall__,json = pcall(require, 'cjson')
  5. json = (__pcall__) and json or require 'tarantool_psql.fallback.json'
  6. ------------------------------
  7. -- functions -----------------
  8. ------------------------------
  9. -- encode json from lua table --
  10. local function encode_json(tbl, escape)
  11. return escape(json.encode(tbl)) .. '::jsonb'
  12. end
  13. -- decode json to lua table --
  14. local function decode_json(str)
  15. return json.decode(str)
  16. end
  17. ------------------------------
  18. return { encode = encode_json, decode = decode_json }