Home
DevCentral
Search
Configure Global Search
Log In
Transactions
T2168
Change Details
Change Details
Old
New
Diff
We've seen with recent Obsidian work AI can directly grasp Vector::map and complete elegant solutions. Consider those two code snippets using chaining methods: ```lang=php $payload = $db ->query($sql) // SELECT with only one row ->fetchMap() ->map(fn ($key, $value) => "$key=$value") ->implode("\n"); ``` $items = $db ->query($sql) // SELECT with several rows ->fetchAllMap() ->map(fn |$row| buildFromRow($row)); ``` // ->map(fn ($key) => $this->fields[$key]);
Keruald Database currently return rows as associative arrays, or indexed arrays if so configured. To process databases result in high order functions, it could be interesting to leverage the work done in Keruald OmniTools to build the HashMap type and have the following methods: - DatabaseResult::fetchRowAsMap : Option<HashMap<String, String>> - DatabaseResult::iterate : generator yielding HashMap<String, String> **Context and how we could leverage this** We've seen with recent Obsidian work AI can directly grasp Vector::map and complete elegant solutions: ```lang=php public function getIndexKeys () : Vector { return Vector::from($this->index) ->map(fn ($key) => $this->fields[$key]); // <- directly an auto complete in PhpStorm } ``` That reinforces the idea to work with those HOF-friendly types by default. Consider those two code snippets using chaining methods to understand what we want to do: ```lang=php $sql = "SELECT ... LIMIT 1"; $payload = $db ->query($sql) ->fetchRowAsMap() ->map(fn ($key, $value) => "$key=$value") ->implode("\n"); ``` A generator to emit hashmaps would be interesting too: ```lang=php $items = $db ->query($sql) // SELECT with several rows ->iterate() ->map(fn ($row) => loadFromRow($row)); ``` (There is definitely a Rust vibe in this)
We've seen with recent Obsidian work AI can directly grasp Vector::map and complete elegant solutions
Keruald Database currently return rows as associative arrays, or indexed arrays if so configured
.
Consider those two code snippets using chaining method
To process databases result in high order functions, it could be interesting to leverage the work done in Keruald OmniTools to build the HashMap type and have the following methods: - DatabaseResult::fetchRowAsMap : Option<HashMap<String, String>> - DatabaseResult::iterate : generator yielding HashMap<String, String> **Context and how we could leverage this** We've seen with recent Obsidian work AI can directly grasp Vector::map and complete elegant solution
s: ```lang=php
public function getIndexKeys () : Vector { return Vector::from($this->index) ->map(fn ($key) => $this->fields[$key]); // <- directly an auto complete in PhpStorm } ``` That reinforces the idea to work with those HOF-friendly types by default. Consider those two code snippets using chaining methods to understand what we want to do: ```lang=php $sql = "SELECT ... LIMIT 1";
$payload = $db ->query($sql)
// SELECT with only one row
->fetch
RowAs
Map() ->map(fn ($key, $value) => "$key=$value") ->implode("\n"); ```
A generator to emit hashmaps would be interesting too:
```lang=php
$items = $db ->query($sql) // SELECT with several rows
->fetchAllMap
->iterate
() ->map(fn
|
(
$row
| buil
) => loa
dFromRow($row)); ```
// ->map(fn ($key) => $this->fields[$key]);
(There is definitely a Rust vibe in this)
Continue