SaltechSystems / couchbase_lite

Flutter plugin for the Community edition of Couchbase Lite. Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Querying boolean property returns as int

mehrdad-shokri opened this issue · comments

Describe the bug
getting property inserted as boolean in int format

To Reproduce
db.saveDocument(MutableDocument()
.setString('type', TYPE)
.setString('title', title)
.setBoolean('done', done));

await QueryBuilder.select([
SelectResult.expression(Meta.id.from(ALIAS)).as('id'),
SelectResult.expression(Expression.property('title').from(ALIAS))
.as('title'),
SelectResult.expression(Expression.property('done')
.from(ALIAS))
.as('done')
])
.from(Constants.DB_NAME, as: ALIAS)
.where(Expression.property('type')
.from(ALIAS)
.equalTo(Expression.string(TYPE)))
.execute()

Expected behavior
Each Result in ResultSet should have a done property with boolean value on it but returned result is an int

I found this, is it related?

I'm not sure on how everything is done behind the scenes but I do know that SQLite is used to store information and SQLite does not have boolean types instead it uses 0's and 1's.

So you're saying this is expected behavior? so why is there setBoolean on MutableDocument if it doesn't support boolean data type

I'm sure its mostly because there is not an easy solution to differentiate between boolean and int values in SQLite / maybe C or C# depending on where the value is being stored. Refer to this documentation on the method getBoolean for a way to parse the value https://pub.dev/documentation/couchbase_lite/latest/couchbase_lite/Document-class.html

@bawelter how do I cast a Result to Document? since QueryBuilder.execute() results ResultSet

@bawelter how do I cast a Result to Document? since QueryBuilder.execute() results ResultSet

Please reference the documentation https://pub.dev/documentation/couchbase_lite/latest/couchbase_lite/Database-class.html for retrieving a Document object and https://pub.dev/documentation/couchbase_lite/latest/couchbase_lite/Result-class.html for using the getBoolean function on a result set. Please refer to the documentation before posting questions here.

I use https://pub.dev/packages/built_value to model the data. Hopefully this helps.