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

Unable to parse and represent certain responses from server #2

Open
BradBot1 opened this issue Aug 3, 2024 · 0 comments
Open

Unable to parse and represent certain responses from server #2

BradBot1 opened this issue Aug 3, 2024 · 0 comments

Comments

@BradBot1
Copy link

BradBot1 commented Aug 3, 2024

As expressed certain queries that are spec compliant have no parse state:

Example

For this have a valid database hosted on :8080 and have a table with a string value entry. For instance the query CREATE TABLE IF NOT EXISTS example (entry TEXT UNIQUE PRIMARY KEY) would work

import gleam/http
import gleam/http/request
import gleam/httpc
import gleam/io
import glibsql/http as glibsql

pub fn main() {
  case
    glibsql.new_request()
    |> glibsql.with_database("")
    |> glibsql.with_token("")
    |> glibsql.with_host("localhost:8080")
    |> glibsql.with_organization("")
    |> glibsql.with_statement(
      glibsql.new_statement()
      |> glibsql.with_query(
        "SELECT exists(SELECT * FROM example WHERE entry=? COLLATE nocase)",
      )
      |> glibsql.with_argument(
        glibsql.AnonymousArgument(glibsql.Text("testing")),
      ),
    )
    |> glibsql.with_statement(glibsql.CloseStatement)
    |> glibsql.build
  {
    Ok(req) ->
      case
        httpc.send(
          req
          // just a hack to force connection to a local server for testing, this does not effect functionality
          |> request.set_host("localhost:8080")
          |> request.set_scheme(http.Http),
        )
      {
        Ok(res) -> glibsql.decode_response(res.body) |> io.debug
        Error(_) -> panic as "Failed to send request"
      }
    Error(_) -> panic as "Failed to build query"
  }
}

The above example will return an Error(Nil) when a 0 is expected

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

1 participant