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

Suggestion for easier more Rust-like commands #170

Open
Raj2032 opened this issue Jun 19, 2022 · 8 comments
Open

Suggestion for easier more Rust-like commands #170

Raj2032 opened this issue Jun 19, 2022 · 8 comments

Comments

@Raj2032
Copy link

Raj2032 commented Jun 19, 2022

Hey @KyGost, I wanted to suggest improvements to multisql.

In this example:

use gluesql::prelude::*;

fn main() {
    let storage = SledStorage::new("data/doc-db").unwrap();
    let mut glue = Glue::new(storage);
    let sqls = vec![
        "DROP TABLE IF EXISTS Glue;",
        "CREATE TABLE Glue (id INTEGER);",
        "INSERT INTO Glue VALUES (100);",
        "INSERT INTO Glue VALUES (200);",
        "SELECT * FROM Glue WHERE id > 100;",
    ];

    for sql in sqls {
        let output = glue.execute(sql).unwrap();
        println!("{:?}", output)
    }
}

While this is great for basic stuff, I wanted to suggest a more cleaner alternative.

Here is my suggestion to use commands to execute stuff such as select etc etc. Here is my example (this is pseudo code):

glue.drop(["Glue"]);
glue.create("Glue", vec![id: INTEGER]); // Takes two arguments, one is for the table name, the other is for column names
glue.insert("Glue", vec!(100);
glue.insert("Glue", vec!(200);
glue.select("Glue", ["*"], [id > 100, id == 100]; // table_name, columns, condition(s)

Unless if there was a way to do this already?

@KyGost
Copy link
Member

KyGost commented Jun 19, 2022

Hey @Raj2032, thanks! Great suggestion.

I've already been working on this in a way, with macros like:
https://github.com/MultiSQL/multisql/blob/main/tests/api/insert.rs#L11

And, in the process, I've been cleaning up the API so things like Glue::insert are better usable.

@Raj2032
Copy link
Author

Raj2032 commented Jun 20, 2022

@KyGost

Hey @Raj2032, thanks! Great suggestion.

No worries mate :)

I've already been working on this in a way, with macros like:
https://github.com/MultiSQL/multisql/blob/main/tests/api/insert.rs#L11

Oh nice, is it ready for use?


Off topic over here but if multisql is different to glue sql, how come there are names with glue sql in your repo?

@KyGost
Copy link
Member

KyGost commented Jun 20, 2022

@Raj2032

Oh nice, is it ready for use?

Yup

Off topic over here but if multisql is different to glue sql, how come there are names with glue sql in your repo?

When I rewrote things, I never bothered changing it. It never seemed inappropriate.

Open to suggestions for alternatives.

@Raj2032
Copy link
Author

Raj2032 commented Jun 20, 2022

@KyGost

Yup

Oh nice mate. What about other things such as SELECT, CREATE TABLE etc?

Is this also available to gluesql as well mate?

When I rewrote things, I never bothered changing it. It never seemed inappropriate.

Ah right mate got it :)

@KyGost
Copy link
Member

KyGost commented Jun 20, 2022

@Raj2032
Not that I'm aware.

@Raj2032
Copy link
Author

Raj2032 commented Jun 20, 2022

@KyGost I see mate.

for multisql do such macros such as SELECT, CREATE TABLE etc exist?

@KyGost
Copy link
Member

KyGost commented Jun 20, 2022

@Raj2032
SELECT: Kinda

Everything else is a TODO

@Raj2032
Copy link
Author

Raj2032 commented Jun 20, 2022

@KyGost AH right thanks mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants