# API Query DB error

**URL:** <https://community.fibery.io/t/api-query-db-error/747>\
**Category:** Bugs & Issues\
**Created:** [June 7, 2020, 1:47pm UTC](https://community.fibery.io/t/api-query-db-error/747 "2020-06-07T13:47:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haslien](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/haslien/32/493_2.png) [@Haslien](https://community.fibery.io/u/Haslien)\
**Post date:** [June 7, 2020, 1:47pm UTC](https://community.fibery.io/t/api-query-db-error/747/1 "2020-06-07T13:47:29Z")

</div>

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

```auto
[{
	"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

```auto
[{
    "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
        	(…)"
    }
}]

```

---

<div class="post-metadata">

**Author:** ![shotkin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/shotkin/32/12_2.png) [@shotkin](https://community.fibery.io/u/shotkin)\
**Post date:** [June 8, 2020, 8:47am UTC](https://community.fibery.io/t/api-query-db-error/747/2 "2020-06-08T08:47:10Z")

</div>

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:

```auto
  [{
	"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"
          }
	}
}]

```

---

<div class="post-metadata">

**Author:** ![Haslien](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/haslien/32/493_2.png) [@Haslien](https://community.fibery.io/u/Haslien)\
**Post date:** [June 8, 2020, 8:58am UTC](https://community.fibery.io/t/api-query-db-error/747/3 "2020-06-08T08:58:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shotkin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/shotkin/32/12_2.png) [@shotkin](https://community.fibery.io/u/shotkin)\
**Post date:** [June 8, 2020, 9:33am UTC](https://community.fibery.io/t/api-query-db-error/747/4 "2020-06-08T09:33:36Z")

</div>

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;

````auto
	"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"
          }
	}
}]```
````

---

<div class="post-metadata">

**Author:** ![Haslien](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/haslien/32/493_2.png) [@Haslien](https://community.fibery.io/u/Haslien)\
**Post date:** [June 8, 2020, 9:41am UTC](https://community.fibery.io/t/api-query-db-error/747/5 "2020-06-08T09:41:46Z")

</div>

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 🙂

Here’s the result:

```auto
[
    {
        "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"
        }
    }
]

```

---

<div class="post-metadata">

**Author:** ![shotkin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/shotkin/32/12_2.png) [@shotkin](https://community.fibery.io/u/shotkin)\
**Post date:** [June 8, 2020, 9:53am UTC](https://community.fibery.io/t/api-query-db-error/747/6 "2020-06-08T09:53:39Z")

</div>

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:

```auto
	"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"
          }
	}
}]
```

---

<div class="post-metadata">

**Author:** ![Haslien](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/haslien/32/493_2.png) [@Haslien](https://community.fibery.io/u/Haslien)\
**Post date:** [June 8, 2020, 9:57am UTC](https://community.fibery.io/t/api-query-db-error/747/7 "2020-06-08T09:57:08Z")

</div>

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! 🙂

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

```auto
[{
	"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**

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

```
