Skip to content
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

Bug: Deno - db.select() is not working as intended when passed an Id #79

Closed
2 tasks done
frownieebrownie opened this issue Apr 11, 2023 · 3 comments · Fixed by #78
Closed
2 tasks done

Bug: Deno - db.select() is not working as intended when passed an Id #79

frownieebrownie opened this issue Apr 11, 2023 · 3 comments · Fixed by #78
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@frownieebrownie
Copy link

frownieebrownie commented Apr 11, 2023

Describe the bug

The documentation for the Deno library suggests that db.select(thing) can be used with either a table or specific record, however when passing a record Id it always fails with the following error:

RecordError: Record not found: department:40r67eog7lini8rorbr5
    at Surreal.#output (https://deno.land/x/surrealdb@v0.5.0/src/index.ts:694:9)
    at Surreal.<anonymous> (https://deno.land/x/surrealdb@v0.5.0/src/index.ts:442:19)
    at Surreal.f (https://deno.land/x/surrealdb@v0.5.0/src/classes/emitter.ts:26:9)
    at https://deno.land/x/surrealdb@v0.5.0/src/classes/emitter.ts:33:10
    at Array.forEach (<anonymous>)
    at Surreal.emit (https://deno.land/x/surrealdb@v0.5.0/src/classes/emitter.ts:32:20)
    at Socket.<anonymous> (https://deno.land/x/surrealdb@v0.5.0/src/index.ts:222:17)
    at https://deno.land/x/surrealdb@v0.5.0/src/classes/emitter.ts:33:10
    at Array.forEach (<anonymous>)
    at Socket.emit (https://deno.land/x/surrealdb@v0.5.0/src/classes/emitter.ts:32:20)

I have also tried running the RPC commands directly on the server using Insomnia which behaves as expected returning the single record when an Id is used as the parameter for select.

There is also a workaround using db.query() but its a bit clunkier.

Steps to reproduce

  1. Create and configure db instance:

SurrealDbmanager.ts

export class SurrealDbManager{
    public static instance: Surreal;

    private constructor() {}

    public static async SetupDb(url: string): Promise<Surreal> {
        try {
            console.log("Setting up db");
            this.instance = new Surreal(url);
            
            await this.instance.signin({
                user: 'root',
                pass: 'root',
            });
    
            await this.instance.use('opsys', 'dashboard')
            return this.instance;
        } catch (error) {
            logger.error(error);
            throw error;
        }
    }

}

index.ts
export const db = await SurrealDbManager.SetupDb('http://10.88.10.27:8000/rpc');

  1. Call Create() and make note of the generated id.
  2. Call GetAll() and confirm the new record exists.
  3. Attempt to retrieve the single record with GetById() using the id of the newly created record

DepartmentRepository.ts

import { db } from "../index.ts";
import { Department } from "../db/models/Department.ts";

export class DepartmentRepository{
    static async GetAll(): Promise<Department[]>{ 
        const departments = await db.select<Department>("departments");
        return departments;
    }

    static async GetById(id: string): Promise<Department>{
        const department = await db.select<Department>(id);
        return department[0];
    }

    static async Create(department: Department): Promise<Department> {
        const newDepartmentRecord = await db.create<Department>(
          'departments',
         department,
        );
        console.log(newDepartmentRecord);
        return newDepartmentRecord;
      }
      
}

Expected behaviour

db.select() should be returning the single record with the specified Id rather than generating an error.

SurrealDB version

1.0.0-beta.9+20230402.5eafebd for linux on x86_64

Contact Details

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@frownieebrownie frownieebrownie added the bug Something isn't working label Apr 11, 2023
@kearfy kearfy transferred this issue from surrealdb/surrealdb Apr 11, 2023
@kearfy
Copy link
Member

kearfy commented Apr 11, 2023

Hey @frownieebrownie, thanks for this! We're working on a fix in #78 which should be merged soon! After that we'll deploy the fix in an update. Please note that this is an issue purely in the client library, the actual request get's processed just fine. (read, when you update a specific record then you will get back a permission error, whilst it was updated just fine)

@kearfy kearfy added the good first issue Good for newcomers label Apr 11, 2023
@kearfy kearfy linked a pull request Apr 11, 2023 that will close this issue
@frownieebrownie
Copy link
Author

@kearfy Amazing. I did notice that could I make the RPC request manually and it worked just fine. Apologies, I should have made the issue on the JS repo rather than here.

@kearfy
Copy link
Member

kearfy commented Apr 11, 2023

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants