sqlpage / SQLPage

Fast SQL-only data application builder. Automatically build a UI on top of SQL queries.
https://sql.datapage.app
MIT License
1.57k stars 89 forks source link

Allowed variable to be used with function "sqlpage.read_file_as_text" #560

Closed florian-bellencontre closed 1 month ago

florian-bellencontre commented 1 month ago

What are you building with SQLPage ?

I'm creating a web interface to manage account creation and management via proftpd. And I want to add a toggle to activate the dark mode.

What is your problem ? A description of the problem, not the solution you are proposing.

I'm looking to use the following toggle example: https://github.com/lovasoa/SQLpage/tree/main/examples/light-dark-toggle

I'd like to use the dynamic component with a file and not by storing the information in a database.

What are you currently doing ? Since your solution is not implemented in SQLPage currently, what are you doing instead ?

I currently have this code:

select 'dynamic' as component, sqlpage.read_file_as_text('shell.json') as properties;

shell.json

{
    "component": "shell",
    "title": "ProFTPD - admin",
    "layout": "vertical",
    "font": "Poppins",
    "icon": "folder-share",
    "__icon_list__": "https://tabler.io",
    "footer": "Infra",
    "link": "/",
    "sidebar": true,
    "theme": "dark",
    "menu_item": [
        {"link": "index.sql", "title": "Home"},
        {"link": "create.sql", "title": "Create SFTP"},
        {"link": "list.sql", "title": "SFTP list"},
        {"title":"☀","link":"/toggle.sql"}
    ]
}

I would like to be able to do this:

{
    "component": "shell",
...
    "theme": sqlpage.cookie('lightdarkstatus'),
...
}

I don't know if this is easily doable but it would be really cool.

Thanks in advance ;)

lovasoa commented 1 month ago

Hi! You can use https://sql.datapage.app/functions.sql?function=run_sql for that!

lovasoa commented 1 month ago

You can do it with

select 'dynamic' as component, sqlpage.run_sql('shell.sql') as properties;

and shell.sql :

select
    'shell' as component,
    sqlpage.cookie('lightdarkstatus') as theme;
florian-bellencontre commented 1 month ago

It works perfectly, thanks for the help and sorry for creating an issue rather than a discussion.