-
Couldn't load subscription status.
- Fork 9
feat:surrealDB queries 39-23 #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Sweep: PR ReviewThis pull request enhances SurrealDB query handling and introduces benchmark testing. The main change involved modifying how Additionally, a new benchmark test was added. The Minor changes included updating test descriptions and filter conditions to improve clarity and accuracy. For example, test cases were renamed to better reflect their purpose, such as changing "ef6[entity,filter] - $filter by unique field" to "ef6[entity,filter,id] - $filter by id in filter". The changelog was updated to reflect these changes, documenting the new version
|
| $var: string; | |
| $fieldType: string; | |
| $filter?: Record<string, string>; | |
| }; |
View Diff
src/stateMachine/query/bql/enrich.ts
- Directly assigning
field.$filterwithout transformation increateRoleFieldmay lead to incorrect filter application if the schema requires key mapping.
blitz-orm/src/stateMachine/query/bql/enrich.ts
Lines 305 to 308 in 1f80eb4
| $intermediary: relation, | |
| $justId, | |
| $id: field.$id, | |
| $filter: field.$filter, |
View Diff
src/stateMachine/query/tql/build.ts
- The
mapFilterKeysfunction does not handle cases wherethingSchemais null or undefined, which could lead to runtime errors. - The
buildFilterfunction now relies onmapFilterKeys, but there is no error handling ifmapFilterKeysreturns an invalid or unexpected filter structure. - Sweep has identified a redundant function: The new function
mapFilterKeysis redundant as its functionality is already covered byprocessFilterandmapPositiveFilterKeys. - Sweep has identified a redundant function: The new function
mapPositiveFilterKeysis redundant because its functionality is already covered by the existingmapFilterKeysfunction, which callsmapPositiveFilterKeysinternally.
blitz-orm/src/stateMachine/query/tql/build.ts
Lines 295 to 315 in 1f80eb4
| const mapFilterKeys = (filter: Filter, thingSchema: EnrichedBormEntity | EnrichedBormRelation) => { | |
| const mapper: Record<string, string> = {}; | |
| thingSchema.dataFields?.forEach((df) => { | |
| if (df.path !== df.dbPath) { | |
| mapper[df.path] = df.dbPath; | |
| } | |
| }); | |
| if (Object.keys(mapper).length === 0) { | |
| return filter; | |
| } | |
| const { $not, ...f } = filter; | |
| const newFilter: Filter = mapPositiveFilterKeys(f, mapper); | |
| if ($not) { | |
| newFilter.$not = mapPositiveFilterKeys($not as PositiveFilter, mapper); | |
| } | |
| return newFilter; |
View Diff
blitz-orm/src/stateMachine/query/tql/build.ts
Lines 327 to 336 in 1f80eb4
| const buildFilter = (props: { | |
| $filter: Filter; | |
| $var: string; | |
| $thing: string; | |
| schema: EnrichedBormSchema; | |
| depth: number; | |
| }) => { | |
| const { $filter: $nonMapedFilter, $var, $thing, schema, depth } = props; | |
| const $filter = mapFilterKeys($nonMapedFilter, getThing(schema, $thing)); | |
View Diff
blitz-orm/src/stateMachine/query/tql/build.ts
Lines 295 to 315 in 1f80eb4
| const mapFilterKeys = (filter: Filter, thingSchema: EnrichedBormEntity | EnrichedBormRelation) => { | |
| const mapper: Record<string, string> = {}; | |
| thingSchema.dataFields?.forEach((df) => { | |
| if (df.path !== df.dbPath) { | |
| mapper[df.path] = df.dbPath; | |
| } | |
| }); | |
| if (Object.keys(mapper).length === 0) { | |
| return filter; | |
| } | |
| const { $not, ...f } = filter; | |
| const newFilter: Filter = mapPositiveFilterKeys(f, mapper); | |
| if ($not) { | |
| newFilter.$not = mapPositiveFilterKeys($not as PositiveFilter, mapper); | |
| } | |
| return newFilter; |
View Diff
blitz-orm/src/stateMachine/query/tql/build.ts
Lines 318 to 324 in 1f80eb4
| const mapPositiveFilterKeys = (filter: PositiveFilter, mapper: Record<string, string>) => { | |
| const newFilter: PositiveFilter = {}; | |
| Object.entries(filter).forEach(([key, filterValue]) => { | |
| const newKey = mapper[key] || key; | |
| newFilter[newKey] = filterValue; | |
| }); | |
| return newFilter; |
View Diff
src/types/requests/queries.ts
- The removal of the
$filterProcessedproperty from theEnrichedRoleQuerytype may break existing logic that relies on this property to determine the processing state of a filter.
blitz-orm/src/types/requests/queries.ts
Lines 118 to 120 in 1f80eb4
| $filterByUnique: boolean; | |
| $playedBy: PlayedBy; | |
| $sort?: Sorter[]; |
View Diff
tests/bench.sh
- The script does not handle potential errors from Docker commands, which could lead to silent failures or incomplete setups.
Lines 6 to 24 in 1f80eb4
| docker run --detach --rm --pull always -v $(pwd)/tests:/tests -p 8000:8000 --name $CONTAINER_NAME surrealdb/surrealdb:latest start --allow-all -u tester -p tester | |
| until [ "`docker inspect -f {{.State.Running}} $CONTAINER_NAME`"=="true" ]; do | |
| sleep 0.1; | |
| done; | |
| # Setup surrealdb database for the surrealdb test | |
| # Create the namespace, database, and user | |
| cat tests/surrealdb/mocks/database.surql | docker exec -i $CONTAINER_NAME ./surreal sql -u tester -p tester | |
| # Create the schema | |
| docker exec -it $CONTAINER_NAME ./surreal import -u tester -p tester --namespace test --database test --endpoint http://localhost:8000 ./tests/surrealdb/mocks/schema.surql | |
| # Insert data | |
| docker exec -it $CONTAINER_NAME ./surreal import -u tester -p tester --namespace test --database test --endpoint http://localhost:8000 ./tests/surrealdb/mocks/data.surql | |
| # Always stop container, but exit with 1 when tests are failing | |
| if CONTAINER_NAME=${CONTAINER_NAME} npx vitest bench $@;then | |
| docker stop ${CONTAINER_NAME} | |
| else | |
| docker stop ${CONTAINER_NAME} && exit 1 |
View Diff
tests/surrealdb/README.md
- The removal of
tests/surrealdb/README.mdeliminates critical setup and testing instructions, which could hinder developers from properly setting up and running tests for SurrealDB.
blitz-orm/tests/surrealdb/README.md
Lines 1 to 29 in 46a6691
| # SurrealDB test | |
| Before we run test, start the db: | |
| ```sh | |
| surreal start file:database.db --allow-all -u tester -p tester | |
| ``` | |
| Then create the database: | |
| ```sh | |
| cat ./tests/surrealdb/mocks/database.surql | surreal sql -u tester -p tester | |
| ``` | |
| Then execute the migration and seed script: | |
| ```sh | |
| surreal import -u tester -p tester --namespace test --database test --endpoint http://localhost:8000 ./tests/surrealdb/mocks/schema.surql | |
| surreal import -u tester -p tester --namespace test --database test --endpoint http://localhost:8000 ./tests/surrealdb/mocks/data.surql | |
| ``` | |
| # Docker | |
| ```sh | |
| docker run --rm --pull always -v $(pwd)/tests:/tests -p 8000:8000 --name borm surrealdb/surrealdb:latest start --allow-all -u tester -p tester | |
| cat tests/surrealdb/mocks/database.surql | docker exec -i borm ./surreal sql -u tester -p tester | |
| docker exec -it borm ./surreal import -u tester -p tester --namespace test --database test --endpoint http://localhost:8000 ./tests/surrealdb/mocks/schema.surql | |
| docker exec -it borm ./surreal import -u tester -p tester --namespace test --database test --endpoint http://localhost:8000 ./tests/surrealdb/mocks/data.surql | |
| ``` |
View Diff
tests/surrealdb/bench/all.bench.ts
- The
initfunction is used without any error handling, which could lead to unhandled exceptions ifinitfails.
blitz-orm/tests/surrealdb/bench/all.bench.ts
Lines 2 to 4 in 1f80eb4
| import { init } from '../helpers/init'; | |
| allBench(init); |
View Diff
Potential Issues
Sweep is unsure if these are issues, but they might be worth checking out.
src/stateMachine/query/bql/enrich.ts
- The removal of the
mapFilterKeysfunction means that filter keys will no longer be transformed based on the schema, which could lead to incorrect filter processing if the schema paths differ from the database paths. - The removal of the
mapFilterKeysfunction and its associated logic means that filters will no longer be transformed based on the schema, which could lead to incorrect filter processing.
blitz-orm/src/stateMachine/query/bql/enrich.ts
Lines 75 to 77 in 1f80eb4
| const currentSchema = getCurrentSchema(schema, node); | |
| if (value.$filter) { | |
| value.$filterByUnique = checkFilterByUnique(value.$filter, currentSchema); |
View Diff
blitz-orm/src/stateMachine/query/bql/enrich.ts
Lines 75 to 77 in 1f80eb4
| const currentSchema = getCurrentSchema(schema, node); | |
| if (value.$filter) { | |
| value.$filterByUnique = checkFilterByUnique(value.$filter, currentSchema); |
View Diff
tests/typedb/bench/all.bench.ts
- The
initfunction is called within the benchmark test without any error handling, which could cause the benchmark to fail ifinitthrows an error.
blitz-orm/tests/typedb/bench/all.bench.ts
Lines 2 to 4 in 1f80eb4
| import { init } from '../helpers/init'; | |
| allBench(init); |
View Diff
package.json was not reviewed because our filter identified it as typically a non-human-readable or less important file (e.g., dist files, package.json, images). If this is an error, please let us know.
|
Sweep: Please fix these: File: tests/bench.sh File: tests/surrealdb/bench/all.bench.ts |
|
❌ An error occured! The exception message is:/tmp/cache/repos/Blitzapps/blitz-orm/b4e33ac3c01cd732fc6f5e85ce06c9d85d6107d5b027f9bd249c8c36a2adcc39/feat-surrealdb-queries/tests/surrealdb/README.md does not exist. The stack trace is:Traceback (most recent call last): Please report this on our community forum. This is an automated message generated by Sweep AI. |
|
Sweep: Please fix these: File: tests/bench.sh File: tests/surrealdb/bench/all.bench.ts Dont explore this file, as it was deleted in this PR, so please dont review it: |
|
❌ An error occured! The exception message is:/tmp/cache/repos/Blitzapps/blitz-orm/617a5e3467d60497fb4105c52b112ca8c9cae585007af96beb9801214aaf4f74/feat-surrealdb-queries/tests/surrealdb/README.md does not exist. The stack trace is:Traceback (most recent call last): Please report this on our community forum. This is an automated message generated by Sweep AI. |
No description provided.