btk5h / skript-db

MIT License
5 stars 5 forks source link

Add support for asynchronous use #9

Closed Spartan9802 closed 6 years ago

Spartan9802 commented 6 years ago

Hey, Could you add support to use skript-db asynchronously, it's not possible at the moment to use it in a function I find it really too bad it's what still pushes me to use Skquery that spam my data bade x)

Snow-Pyon commented 6 years ago

Skript-db is asynchronously already, the thing is that it is a delayed effect and thus, it doesn't work on functions.

There are a lot of alternatives to functions though, such as custom syntaxes from skript-mirror.

Spartan9802 commented 6 years ago

I tested with skript-mirror expressions but it doesn't work ^^

on script load:
    set {sql} to the database "mysql://localhost:3306/test?user=root&password=&useSSL=false"

expression getValue:
    get:
        execute "select * from data" in {sql} and store the result in {_output::*}
        return {_output::*}

command /dbtest:
    trigger:
        set {_output::*} to getValue
        send "%{_output::*}%"

This return null

Snow-Pyon commented 6 years ago

you can't have delayed expressions the same way you can't have delayed functions with return. Use an effect.

Also, why would you use a function in that case? You could directly use the effect in the command and it'd be the same.

Spartan9802 commented 6 years ago

It's just for example ^^ Otherwise I use the functions for my inventorysaver on every death, world change, etc. the inventory is saved in database and it is possible to regive it via an interface

But it's not possible to get back on an effect?

Spartan9802 commented 6 years ago

So have you thought about my request?

btk5h commented 6 years ago

skript-db already executes queries asynchronously. The issue is that expressions cannot be asynchronous or contain any delays.

The solution is to create a delayed custom effect to send your requests, store the results in a variable, and create a custom expression to return the results.