#sqlite plugin doesn't run functions?

11 messages · Page 1 of 1 (latest)

modest temple
#

Hi! I'm new to Tauri and sqlite, so I'm probably doing something wrong, but using the sqlite plugin I can't run functions.

For example:

await db.select('SELECT max(id) from tasks')

returns an object:

{0 : {max(id): null}}```
The same if I do
```JavaScript
await db.select('SELECT last_insert_rowid()');
//returns '{0 : {last_insert_rowid(): null}}'

Probably have guessed I'm trying to get the last id of a table. But I don't understand why does SELECTs don't work.

If I'm just misunderstanding sqlite just tell me and I go back to study.

PD (not related with the functions that don't work but with the last id): Also tried with execute as it seems to return the last id, but

await db.execute('SELECT * from tasks')
//returns { rowsAffected: 0, lastInsertId: 0 }

which is not even ok, as the db has 3 rows that I can clearly read with db.select('SELECT * FROM tasks') with ids 1, 2 and 3.

fast wraith
#

Run: select name from sqlite_master; this should return all of your tables. If it comes back empty then your problem is with the schema

modest temple
#

Returns an array with the name of my only table. Idk if it should show something else, like the content. I suppose that SELECT name means only the name, so that should be ok?

#

The table is not empty and I can read it with SELECT *

fast wraith
#

right so its a query issue most likely, I don't use the MAX keyword that often so I wouldn't know but it should work

#

a useful site to visit is http://SQLime.org, great way to test your schema and queries

modest temple
#

Will play with it. I suppose that if I can't make it work I should ask in a sqlite server/forum.

#

Thanks

fast wraith
#

last bit of advice, adding ; is pretty standard and I wouldn't be surprised if that caused the problem. And there may be an issue with the official Sqlite problem, at least when it came to column types. maybe that pr got resolved.
this is also a pretty good plugin: https://github.com/lzdyes/tauri-plugin-sqlite
And it may be better to implement it in rust, but you can look into that yourself.

GitHub

A Tauri plugin for interface to SQLite. Contribute to lzdyes/tauri-plugin-sqlite development by creating an account on GitHub.

modest temple
#

Oh, I tried the official because I thought "offical > unofficial", but will try the other one.

#

I'm just too beginner to Rust so my plan to implement it in TypeScript and move it slowly to Rust later. I feel that learning everything together will make it worse for me 😅