Comments (11)
your usage of useLiveQuery seems a bit odd
I encountered cases where the query would not live update as expected. Then I found these docs: https://electric-sql.com/docs/integrations/frontend/react#query-dependencies
That solved my issue. Since then this is how I used it.
from electric.
Right, i see. The error seems to occur when trying to validate the data that is being read from the database using the Zod schema. So indeed, internally the boolean value is a number (0 or 1) and our data access library takes care of converting those to JavaScript booleans. Probably what's happening is that the number is not being converted back to a boolean when reading from the database and thus Zod complains. Will need to investigate this further.
from electric.
VAX-1460 query including referenced table errors sometimes
from electric.
Some more info:
The tables mentioned above are defined like this:
CREATE TABLE projects(
project_id uuid PRIMARY KEY DEFAULT NULL, -- public.uuid_generate_v7(),
account_id uuid DEFAULT NULL REFERENCES accounts(account_id) ON DELETE CASCADE ON UPDATE CASCADE,
name text DEFAULT NULL,
label_replace_by_generated_column text DEFAULT NULL,
type text DEFAULT NULL,
subproject_name_singular text DEFAULT NULL,
subproject_name_plural text DEFAULT NULL,
subproject_order_by text DEFAULT NULL,
values_on_multiple_levels text DEFAULT NULL,
multiple_action_values_on_same_level text DEFAULT NULL,
multiple_check_values_on_same_level text DEFAULT NULL,
data jsonb DEFAULT NULL,
files_active_projects boolean DEFAULT NULL,
files_active_projects_reports boolean DEFAULT NULL,
files_active_subprojects boolean DEFAULT NULL,
files_active_subproject_reports boolean DEFAULT NULL,
files_active_places boolean DEFAULT NULL,
files_active_actions boolean DEFAULT NULL,
files_active_checks boolean DEFAULT NULL,
files_active_check_reports boolean DEFAULT NULL,
deleted boolean DEFAULT NULL
);
CREATE TABLE subprojects(
subproject_id uuid PRIMARY KEY DEFAULT NULL,
account_id uuid DEFAULT NULL REFERENCES accounts(account_id) ON DELETE CASCADE ON UPDATE CASCADE,
project_id uuid DEFAULT NULL REFERENCES projects(project_id) ON DELETE CASCADE ON UPDATE CASCADE,
name text DEFAULT NULL,
label_replace_by_generated_column text DEFAULT NULL,
since_year integer DEFAULT NULL,
data jsonb DEFAULT NULL,
deleted boolean DEFAULT NULL
);
from electric.
Hi @barbalex, the error Zod throws seems to be unrelated to what you're describing.
Zod is complaining that you're passing a number to a property "use_for_action_values" but it is expecting a boolean.
A wild guess would be that you have a column called "use_for_action_values" of some number type and you are including it as follows:
include: {
use_for_action_values: someNumber
}
Inside include
, the value of the use_for_action_values
property should be a boolean (indicating whether or not it should be included) or a nested include object (if that property represents a related table), e.g.:
include: {
use_for_action_values: {
include: {
...
}
}
}
from electric.
PS: your usage of useLiveQuery
seems a bit odd.
It would be better to use it as follows:
const { error, results } = useLiveQuery(
db.projects.liveMany(queryParam)
)
i.e. you just have to call a live query inside the useLiveQuery
hook.
Like this, db.projects
should provide you additional type information and should even complain if your queryParam
has the wrong type.
from electric.
To the main issue.
I am not including anything else then:
If the queryTable is 'subprojects' and the queryParam is:
{
include: {
projects: true
}
where: {
deleted: false
}
}
In this query the exact error mentions: expected boolean, received number
, referring to the field files_active_projects
. That is one of the boolean fields existing in the projects table. It is set to true
when new projects are created.
I have no idea why the error occurs.
One thing I do not completely understand is the usage of boolean values. As far as I understand I can ignore that sqlite expects 0 and 1 and simply use true and false in my client side code. As happens, when setting files_active_projects
to true
in new projects. And also when filtering for not deleted rows in above query params. Is that a correct assumption?
from electric.
What I dont get is why this works when projects are queried, including the subprojects. The result of the query then is:
In this case the included subproject table also has a boolean field, preset to false. That seems to be no problem.
On the other hand when I include projects when querying subprojects, the files_active_projects
column, preset to true, seems to cause a problem.
from electric.
By the way: I have adjusted the query to not use a function and the error prevails:
const { results, error } = useLiveQuery(db[queryTable]?.liveMany(queryParam))
from electric.
Because above dynamic query introduces some more complexity, I have tried including projects in the subproject form that uses this query:
const { results, error } = useLiveQuery(
db.subprojects.liveUnique({
where: { subproject_id },
include: { projects: true },
}),
)
Same error. Here the full error:
{
"issues": [
{
"code": "invalid_union",
"unionErrors": [
{
"issues": [
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_projects"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_projects_reports"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_subprojects"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_subproject_reports"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_places"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_actions"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_checks"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_check_reports"
],
"message": "Expected boolean, received number"
},
{
"code": "unrecognized_keys",
"keys": [
"account_id"
],
"path": [],
"message": "Unrecognized key(s) in object: 'account_id'"
}
],
"name": "ZodError"
},
{
"issues": [
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_projects"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_projects_reports"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_subprojects"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_subproject_reports"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_places"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_actions"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_checks"
],
"message": "Expected boolean, received number"
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "number",
"path": [
"files_active_check_reports"
],
"message": "Expected boolean, received number"
}
],
"name": "ZodError"
}
],
"path": [],
"message": "Invalid input"
}
],
"name": "ZodError"
}
from electric.
I tried this again in v0.9.0 and it works.
Thanks!
from electric.
Related Issues (20)
- Can't load data when phone is offline in Expo app HOT 5
- [BUG] Syntax error CREATE_REPLICATION_SLOT when install electric-sql with docker HOT 8
- MODULE ERROR: Electric.Replication.PostgresConnector HOT 5
- Possible issue in the new ShapeManager code. HOT 3
- SQLite/PGLite not fully compatible with NextJS HOT 4
- Inactive replication slot causing warnings on DO managed Postgres HOT 6
- Demo example with PostGis plugin?? HOT 1
- Error: FOREIGN KEY constraint failed HOT 4
- [rpc] recv: #SatInStartReplicationResp{`Error: Cannot catch up to the server's current state`} HOT 1
- Unable to install electric-sql on MacOS & Node@22 HOT 2
- Zod rejects UUIDs that Postgres deems valid HOT 1
- `(FunctionClauseError) no function clause matching in Electric.Postgres.Extension.SchemaCache.name/1` HOT 7
- too many arguments on function json_object HOT 2
- Issue with ElectricSQL when I try to change the content of an entry in the database HOT 3
- tauri-sqlite example start failed HOT 2
- Secure auth invalid key HOT 6
- Checkout and Linear example not working (client side issue) HOT 1
- Sync service complains about multiple connections from the same client HOT 1
- Fly deploy (launch) of Quickstart app fails HOT 10
- JSONB columns now return as `string` rather than `object` in 0.12.0 HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electric.