API Query DB error

Trying to get an existing item from Fibery results in DB error.

[{
	"command":"fibery.entity/query",
	"args": {
		"query": {
			"q/from": "Berryfi/Task",
			"q/where": ["==", ["Berryfi/name"], "Create a query for making a new type"],
			"q/select": ["fibery/creation-date"],
			"q/limit": 1
		}
	}
}]

Response

[{
    "success": false,
    "result":
    {
        "message": "DB error occurred.",
        "name": "db.error",
        "trace": "clojure.lang.ExceptionInfo: DB error occurred.\n
			{:error/name :db.error, :error/sql}\n
        	at core.error$error.invokeStatic(error.clj: 90)\n
        	core.error$error.invoke(error.clj: 84)\n
        	entity.errors$db_error.invokeStatic(errors.clj: 451)\n
        	entity.errors$db_error.invoke(errors.clj: 450)\n
        	entity.rel.jdbc$with_db_transaction.invokeStatic(jdbc.clj: 140)\n
        	entity.rel.jdbc$with_db_transaction.invoke(jdbc.clj: 136)\n
        	entity.rel.jdbc$with_db_transaction$fn__23775.invoke(jdbc.clj: 200)\n
        	entity.rel.jdbc$with_db_connection$fn__23732.invoke(jdbc.clj: 99)\n
        	entity.rel.jdbc$with_db_connection.invokeStatic(jdbc.clj: 89)\n
        	entity.rel.jdbc$with_db_connection.invoke(jdbc.clj: 84)\n
        	entity.rel.jdbc$with_db_transaction.invokeStatic(jdbc.clj: 200)\n
        	ntity.rel.jdbc$with_db_transaction.invoke(jdbc.clj: 136)\n
        	entity.rel.jdbc$exec_db_query$fn__23796.invoke(jdbc.clj: 238)\n
        	entity.rel.jdbc$exec_db_query.invokeStatic(jdbc.clj: 237)\n
        	entity.rel.jdbc$exec_db_query.invoke(jdbc.clj: 228)\n
        	entity.rel.jdbc$exec_db_query.invokeStatic(jdbc.clj: 229)\n
        	entity.rel.jdbc$exec_db_query.invoke(jdbc.clj: 228)\n
        	entity.db$do_exec_sql_cmd_BANG_.invokeStatic(db.clj: 1012)\n
        	entity.db$do_exec_sql_cmd_BANG_.invoke(db.clj: 1009)\n
        	entity.db$exec_sql_cmd_BANG_.invokeStatic(db.clj: 1031)\n
        	entity.db$exec_sql_cmd_BANG_.invoke(db.clj: 1029)\n
        	entity.db$exec_BANG_.invokeStatic(db.clj: 1043)\n
        	entity.db$exec_BANG_.invoke(db.clj: 1037)\n
        	entity.db$exec_plan_BANG_$fn__29074.invoke(db.clj: 357)\n
        	entity.query.plan_executor$exec_query.invokeStatic(plan_executor.clj: 39)\n
        	(…)"
    }
}]

Hi!
Query language does not support constants in query expressions so you need to pass them explicitly via ‘params’ map and param name starting with ‘$’.
So your query will be following:

  [{
	"command":"fibery.entity/query",
	"args": {
		"query": {
			"q/from": "Berryfi/Task",
			"q/where": ["==", ["Berryfi/name"], "$name"],
			"q/select": ["fibery/creation-date"],
			"q/limit": 1
	 	},
        "params": {
            "$name":"Create a query for making a new type"
          }
	}
}]
1 Like

I thought that was case from looking at the documentation, so I tried that as well yesterday, but to no avail. I tried again now just to make sure, and I still get DB error.

Oh, it seems that we need to fix wrong sample in documentation, can you show me that documentation part, please?

Show me, please, error of executing this query;

	"command":"fibery.entity/query",
	"args": {
		"query": {
			"q/from": "Berryfi/Task",
			"q/where": ["==", ["Berryfi/name"], "$name"],
			"q/select": ["fibery/creation-date"],
			"q/limit": 1
	 	},
        "params": {
            "$name":"Create a query for making a new type"
          }
	}
}]```
1 Like

I may have worded that last post wrong, I mean I expected that you needed to use params to pass variables, and it was the first thing I tried, and the OP was the last thing I tried :slight_smile:

Here’s the result:

[
    {
        "success": false,
        "result": {
            "message": "DB error occurred.",
            "name": "db.error",
            "trace": "clojure.lang.ExceptionInfo: DB error occurred.\n{:error/name :db.error, :error/sql \"\"}\n at core.error$error.invokeStatic (error.clj:90)\n    core.error$error.invoke (error.clj:84)\n    entity.errors$db_error.invokeStatic (errors.clj:451)\n    entity.errors$db_error.invoke (errors.clj:450)\n    entity.rel.jdbc$with_db_transaction.invokeStatic (jdbc.clj:140)\n    entity.rel.jdbc$with_db_transaction.invoke (jdbc.clj:136)\n    entity.rel.jdbc$with_db_transaction$fn__23775.invoke (jdbc.clj:200)\n    entity.rel.jdbc$with_db_connection$fn__23732.invoke (jdbc.clj:99)\n    entity.rel.jdbc$with_db_connection.invokeStatic (jdbc.clj:89)\n    entity.rel.jdbc$with_db_connection.invoke (jdbc.clj:84)\n    entity.rel.jdbc$with_db_transaction.invokeStatic (jdbc.clj:200)\n    entity.rel.jdbc$with_db_transaction.invoke (jdbc.clj:136)\n    entity.rel.jdbc$exec_db_query$fn__23796.invoke (jdbc.clj:238)\n    entity.rel.jdbc$exec_db_query.invokeStatic (jdbc.clj:237)\n    entity.rel.jdbc$exec_db_query.invoke (jdbc.clj:228)\n    entity.rel.jdbc$exec_db_query.invokeStatic (jdbc.clj:229)\n    entity.rel.jdbc$exec_db_query.invoke (jdbc.clj:228)\n    entity.db$do_exec_sql_cmd_BANG_.invokeStatic (db.clj:1012)\n    entity.db$do_exec_sql_cmd_BANG_.invoke (db.clj:1009)\n    entity.db$exec_sql_cmd_BANG_.invokeStatic (db.clj:1031)\n    entity.db$exec_sql_cmd_BANG_.invoke (db.clj:1029)\n    entity.db$exec_BANG_.invokeStatic (db.clj:1043)\n    entity.db$exec_BANG_.invoke (db.clj:1037)\n    entity.db$exec_plan_BANG_$fn__29074.invoke (db.clj:357)\n    entity.query.plan_executor$exec_query.invokeStatic (plan_executor.clj:39)\n    entity.query.plan_executor$exec_query.invoke (plan_executor.clj:31)\n    entity.query.plan_executor$do_exec_plan_expr$fn__25930$fn__25935$fn__25936.invoke (plan_executor.clj:112)\n    entity.query.plan_executor$do_exec_plan_expr$fn__25930$fn__25935.invoke (plan_executor.clj:106)\n    entity.query.plan_executor$do_exec_plan_expr$fn__25930.invoke (plan_executor.clj:106)\n    entity.query.plan_executor$do_exec_plan_expr.invokeStatic (plan_executor.clj:106)\n    entity.query.plan_executor$do_exec_plan_expr.invoke (plan_executor.clj:105)\n    entity.query.plan_executor$exec_let_expr$fn__25835.invoke (plan_executor.clj:60)\n    clojure.core.protocols$fn__8159.invokeStatic (protocols.clj:168)\n    clojure.core.protocols/fn (protocols.clj:124)\n    clojure.core.protocols$fn__8114$G__8109__8123.invoke (protocols.clj:19)\n    clojure.core.protocols$seq_reduce.invokeStatic (protocols.clj:31)\n    clojure.core.protocols$fn__8146.invokeStatic (protocols.clj:75)\n    clojure.core.protocols/fn (protocols.clj:75)\n    clojure.core.protocols$fn__8088$G__8083__8101.invoke (protocols.clj:13)\n    clojure.core$reduce.invokeStatic (core.clj:6828)\n    clojure.core$reduce.invoke (core.clj:6810)\n    entity.query.plan_executor$exec_let_expr.invokeStatic (plan_executor.clj:59)\n    entity.query.plan_executor$exec_let_expr.invoke (plan_executor.clj:57)\n    entity.query.plan_executor$do_exec_plan_expr$fn__25930$fn__25935.invoke (plan_executor.clj:111)\n    entity.query.plan_executor$do_exec_plan_expr$fn__25930.invoke (plan_executor.clj:106)\n    entity.query.plan_executor$do_exec_plan_expr.invokeStatic (plan_executor.clj:106)\n    entity.query.plan_executor$do_exec_plan_expr.invoke (plan_executor.clj:105)\n    entity.query.plan_executor$exec_let_expr.invokeStatic (plan_executor.clj:63)\n    entity.query.plan_executor$exec_let_expr.invoke (plan_executor.clj:57)\n    entity.query.plan_executor$do_exec_plan_expr$fn__25930$fn__25935.invoke (plan_executor.clj:111)\n    entity.query.plan_executor$do_exec_plan_expr$fn__25930.invoke (plan_executor.clj:106)\n    entity.query.plan_executor$do_exec_plan_expr.invokeStatic (plan_executor.clj:106)\n    entity.query.plan_executor$do_exec_plan_expr.invoke (plan_executor.clj:105)\n    entity.query.plan_executor$exec_plan$fn__25958.invoke (plan_executor.clj:122)\n    entity.query.plan_executor$exec_plan.invokeStatic (plan_executor.clj:121)\n    entity.query.plan_executor$exec_plan.invoke (plan_executor.clj:120)\n    entity.db$exec_plan_BANG_.invokeStatic (db.clj:345)\n    entity.db$exec_plan_BANG_.invoke (db.clj:343)\n    entity.db$exec_query_BANG_.invokeStatic (db.clj:426)\n    entity.db$exec_query_BANG_.invoke (db.clj:397)\n    commands.entity$fibery_entity_core_query$fn__47112.invoke (entity.clj:1299)\n    commands.entity$fibery_entity_core_query.invokeStatic (entity.clj:1297)\n    commands.entity$fibery_entity_core_query.invoke (entity.clj:1297)\n    clojure.lang.Var.invoke (Var.java:388)\n    core.command$exec_cmd_with_effects.invokeStatic (command.clj:140)\n    core.command$exec_cmd_with_effects.invoke (command.clj:137)\n    core.command$exec_cmd_with_cache.invokeStatic (command.clj:177)\n    core.command$exec_cmd_with_cache.invoke (command.clj:166)\n    core.command$exec_cmd_with_redis_cache.invokeStatic (command.clj:180)\n    core.command$exec_cmd_with_redis_cache.invoke (command.clj:179)\n    core.command$exec$fn__30664.invoke (command.clj:248)\n    core.command$with_db$fn__30"
        }
    }
]

Oh, there is no ‘==’ equal operator, but ‘=’ is used.

For now working with API is a challenge but we are working on clear error messages!

So correct query is following:

	"command":"fibery.entity/query",
	"args": {
		"query": {
			"q/from": "Berryfi/Task",
			"q/where": ["=", ["Berryfi/name"], "$name"],
			"q/select": ["fibery/creation-date"],
			"q/limit": 1
	 	},
        "params": {
            "$name":"Create a query for making a new type"
          }
	}
}]
1 Like

I tried single = previously and got abstract invalid query error, but never tried pairing with combination of using params as well.

This worked, and I got the expected query result. Thank you! :slight_smile:

Edit: Here’s the query + result for anyone that happen upon this post.
Query

[{
	"command":"fibery.entity/query",
	"args": {
		"query": {
			"q/from": "Berryfi/Task",
			"q/where": ["=", ["Berryfi/name"], "$name"],
			"q/select": ["fibery/creation-date"],
			"q/limit": 1
	 	},
        "params": {
            "$name":"Create a query for making a new type"
          }
	}
}]

Result

[{
    "success": true,
    "result": [
        {
            "fibery/creation-date": "2020-06-06T23:38:06.967Z"
        }
    ]
}]
1 Like