sqlight icon indicating copy to clipboard operation
sqlight copied to clipboard

API for accessing column names and types

Open dvic opened this issue 10 months ago • 4 comments

In Esqlite we can do

    %% All columns
    {ok, Stmt} = esqlite3:prepare(Db, "select * from test_table"),
    ?assertEqual([<<"varchar(10)">>, <<"INT">>], esqlite3:column_decltypes(Stmt)),

and

{ok, Stmt} = esqlite3:prepare(C, "select 1 as one"),
    ?assertEqual([<<"one">>], esqlite3:column_names(Stmt)),

    {ok, Stmt1} = esqlite3:prepare(C, <<"select 1 as 😀"/utf8>>),
    ?assertEqual([<<"😀"/utf8>>], esqlite3:column_names(Stmt1)),
    
    {ok, Stmt2} = esqlite3:prepare(C, <<"select 1">>),
    ?assertEqual([<<"1">>], esqlite3:column_names(Stmt2)),

(copied from one of the tests)

Can we somehow support this as well? (without necessarily exposing prepared statements and such)?

My use case: I'm trying to write a ascii table snapshot of parts of my database and I want to be able to do this dynamically without knowing the columns upfront.

dvic avatar Jan 21 '25 14:01 dvic

Sounds good to have!

lpil avatar Jan 21 '25 17:01 lpil

Was there a reason you left out prepared statements from the API? Is that the preferred approach for this feature or did you have something else in mind? Like query_with_metadata?

dvic avatar Jan 21 '25 18:01 dvic

No reason, and I don't have any ideas.

lpil avatar Jan 21 '25 22:01 lpil

No reason, and I don't have any ideas.

Cool, then I'll see if we can have a prepared statement api that covers both esqlite and the deno library!

dvic avatar Jan 21 '25 22:01 dvic