lpil / lpil/sqlight

Add insert example to docs

Open
#18 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Gleam
Stars
159
Forks
27
PR merge metrics
No merged PRs in 30d

Description

Hello! From experience, inserting into SQLite databases has been a common hurdle for people new to Gleam (for the people that are using SQLite of course). What do you think of updating the docs somewhere to show an example of running an insert statement with a `sqlight.query` call?

Maybe something like this, moving one part of the data into a separate insert statement?

```gleam
import gleam/dynamic/decode
import sqlight

pub fn main() {
use conn <- sqlight.with_connection(":memory:")
let cat_decoder = {
use name <- decode.field(0, decode.string)
use age <- decode.field(1, decode.int)
decode.success(#(name, age))
}

let sql = "
create table cats (name text, age int);

insert into cats (name, age) values
('Nubi', 4),
('Biffy', 10);
"

let assert Ok(Nil) = sqlight.exec(sql, conn)

let sql = "insert into cats (name, age) values (?, ?)"

let assert Ok([]) =
sqlight.query(
sql,
on: conn,
with: [sqlight.text("Ginny"), sqlight.int(6)],
expecting: decode.int,
)

let sql = "
select name, age from cats
where age < ?
"

let assert Ok([#("Nubi", 4), #("Ginny", 6)]) =
sqlight.query(sql, on: conn, with: [sqlight.int(7)], expecting: cat_decoder)
}

```

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 by locating the project's documentation entry point and existing SQLite or sqlight.query examples. Add a runnable example showing an insert with parameter values, then verify the surrounding documentation remains consistent; done means newcomers can see how to execute an insert and retrieve the resulting row.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite
Domain
databases, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.