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

SELECT * seems broken #1

Open
aguynamedben opened this issue Jun 3, 2023 · 1 comment
Open

SELECT * seems broken #1

aguynamedben opened this issue Jun 3, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@aguynamedben
Copy link

🙏 This is a sweet looking library. I wanted to use Tantivy is WASM but it's a pain, so I'm hoping I can get this working in WASM.

The in-memory example in the README doesn't work and I think it's because query parsing is broken for SELECT *. Changing SELECT * to SELECT users.name works fine.

use reefdb::InMemoryReefDB;

fn main() {
    test_readme_in_memory_example();
    test_readme_in_memory_example_FIXED();
    // test_inner_join();
    // test_fts_text_search();
}

// It seems that `SELECT *` isn't working. The _FIXED version of the function
// below does `SELECT users.name` and that works.
fn test_readme_in_memory_example() {
    let mut db = InMemoryReefDB::new();

    let queries = vec![
        "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)",
        "INSERT INTO users VALUES (1, 'Alice')",
        "INSERT INTO users VALUES (2, 'Bob')",
        "SELECT * FROM users WHERE id = 1",
    ];

    for query in queries {
        let result = db.query(query);
        println!("Result: {:?}", result);
    }
}

fn test_readme_in_memory_example_FIXED() {
    let mut db = InMemoryReefDB::new();

    let queries = vec![
        "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)",
        "INSERT INTO users VALUES (1, 'Alice')",
        "INSERT INTO users VALUES (2, 'Bob')",
        "SELECT users.name FROM users WHERE id = 1",
    ];

    for query in queries {
        let result = db.query(query);
        println!("Result: {:?}", result);
    }
}

Output:

Result: Ok(CreateTable)
Result: Ok(Insert(1))
Result: Ok(Insert(1))
Failed to parse statement: Parsing Error: Error { input: "SELECT * FROM users WHERE id = 1", code: Tag }
Result: Err(Other("Parsing Error: Error { input: \"SELECT * FROM users WHERE id = 1\", code: Tag }"))
Result: Ok(CreateTable)
Result: Ok(Insert(1))
Result: Ok(Insert(1))
Result: Ok(Select([(0, [Text("Alice")])]))
@sachaarbonel
Copy link
Owner

sachaarbonel commented Jun 3, 2023

Ah sorry looks I messed up the README. Yeah, it only supports select columns for now. As for wasm, I don't know if it would work out of the box, the in-memory one maybe but for the persisting one, I think you'll need to implement your own trait because of std::File not being wasm compatible, and serialize/deserialize from/to localstorage. Please share your findings if you manage to get it working with wasm

@sachaarbonel sachaarbonel added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants