luckyframework / luckyframework/avram

Clean up crystal-db proxy methods with correct usage

Open
#801 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clarify api
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

https://github.com/luckyframework/avram/blob/519213e5c5f6a7a61766d16e815a2f6220500cae/src/avram/database.cr#L87-L123

Using these low-level crystal-db methods give a false sense of unified code in how they work. For example, it *looks* like you can do this, but you can't...

```crystal
# assume this returns a single SpecialModel
AppDatabase.query(sql, args: [1], as: SpecialModel)

# assume this returns an Array(SpecialModel)
AppDatabase.query_all(sql, args: [1], as: SpecialModel)
```

The issue here is that `query` actually returns a `ResultSet` which could either be a single record or an array of records... There's no `as:` named arg for `query`.

Ref: https://github.com/will/crystal-pg/issues/202

The reason we map these though is so we can properly log them through Avram (and Dexter). I'm sure there's other wrong uses in here, but they should all be cleaned up.

Contributor guide

Open the contributing guide

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 src/avram/database.cr at lines 87-123 and compare each proxy with the crystal-db and crystal-pg usage described in the issue and linked reference. Check that the proxies use correct method signatures while retaining Avram and Dexter logging; done means the incorrect mappings and other wrong uses in this section are cleaned up.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
databases
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.