Skip to content

Unable to parse and represent certain responses from server #2

@BradBot1

Description

@BradBot1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions