moonbit-community / moonbit-community/postgres.mbt

Implement ToSql for StringView

Open Beginner friendly
#20 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
MoonBit
Stars
9
Forks
2
Avg merge
2h 4m
Merged PRs (30d)
1

Description

ToSql is implemented for String, but not StringView, in moonbit-community/postgres@0.0.6. The implementation is also missing from the current main branch.

This means callers that already have a string view, for example from parsing or splitting input, cannot bind it directly as a text parameter:

// @client is moonbit-community/postgres/client.
async fn echo(client : @client.Client, value : StringView) -> Unit {
  ignore(client.query_one("SELECT $1::text", params=[value]))
}

The current workaround is params=[value.to_owned()], which requires an intermediate owned String just to bind the parameter.

Could we add ToSql for StringView, accepting the same PostgreSQL types and using the same text encoding behavior as the existing String implementation in client/scalars.mbt? This would let callers pass string views directly.

Related: #2.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in client/scalars.mbt by reading the existing ToSql implementation for String and compare its accepted PostgreSQL types and text encoding behavior. Add the corresponding StringView support, then verify the issue's query example can bind a StringView directly without calling to_owned.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql
Domain
database
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.