Thread overview
sqlite3 library which can read class instances (not structs)?
Mar 10
Sergey
March 06

Is there a sqlite3 interface library which can correctly read into instances? sqlite3-d will let me compile with a class, but it segv's when run. ddbc seems to support only structs, and I can use it to punch in one value at a time out of each row result. But that feels clunky, and I'd avoid it if I could.

Thanks,
Andy

March 10

On Thursday, 6 March 2025 at 23:45:01 UTC, Andy Valencia wrote:

>

Is there a sqlite3 interface library which can correctly read into instances? sqlite3-d will let me compile with a class, but it segv's when run. ddbc seems to support only structs, and I can use it to punch in one value at a time out of each row result. But that feels clunky, and I'd avoid it if I could.

Dug deeper into sqlite3-d, and see the problem. Is there a static-if which can tell if a type is of a struct, as opposed to a class? I see ones for a final class, or an abstract one. But nothing jumps out to let me know the correct way in a template method to allocate a struct instance as distinct from a class.

Something like:

>

static if (__traits(isClass, T)) {
...
} else if (__traits(isStruct, T)) {
...
} else {
(failure)
}

Thanks,
Andy

March 10

On Thursday, 6 March 2025 at 23:45:01 UTC, Andy Valencia wrote:

>

Is there a sqlite3 interface library which can correctly read into instances? sqlite3-d will let me compile with a class, but it segv's when run. ddbc seems to support only structs, and I can use it to punch in one value at a time out of each row result. But that feels clunky, and I'd avoid it if I could.

Thanks,
Andy

Did you try d2sqlite3?

March 10

On Monday, 10 March 2025 at 21:39:39 UTC, Sergey wrote:

>

Did you try d2sqlite3?

I looked at it, and it only documented struct operations. Given that I now understand the problem at hand, I'd rather go with a fix here than start over.

Thanks,
Andy

March 10
On 3/10/25 2:31 PM, Andy Valencia wrote:

> Is there a static-if
> which can tell if a type is of a struct, as opposed to a class?

[...]

> Something like:
>
>> static if (__traits(isClass, T)) {
>>    ...
>> } else if (__traits(isStruct, T)) {
>>    ...
>> } else {
>>    (failure)
>> }
>
> Thanks,
> Andy
>

You would expect that to be provided by one of the following:

  https://dlang.org/phobos/std_traits.html

  https://dlang.org/spec/traits.html

But in this case it's the "is expression":

  https://dlang.org/spec/expression.html#is_expression

static assert (is (S == struct));

Ali

March 10
On Monday, 10 March 2025 at 22:55:03 UTC, Ali Çehreli wrote:
> You would expect that to be provided by one of the following:
>
>   https://dlang.org/phobos/std_traits.html
>
>   https://dlang.org/spec/traits.html
>
> But in this case it's the "is expression":
>
>   https://dlang.org/spec/expression.html#is_expression
>
> static assert (is (S == struct));


I don't know how long I would have hunted for that without finding it.  Thank you!

Andy