Files
sqlpage--sqlpage/AGENTS.md
Ophir LOJKINE 2af95a041f Accept header JSON responses (#1127)
* Support JSON responses via Accept header

* no update in migrations

* No UPDATE in official site migrations

- Updated the JSON component description to clarify its integration with external services and the ability to serve both HTML and JSON based on the HTTP Accept header.
- Added examples demonstrating how to request JSON responses using `curl`.
- Removed the obsolete migration file that documented the JSON response format feature, consolidating information into the main documentation.

* revert stupid docs example change

stupid bot

* simplify tests

* avoid string then json in tests, parse as json directly

* changelog
2025-11-24 23:17:19 +01:00

47 lines
2.1 KiB
Markdown

Core Concept: User writes .sql files, SQLPage executes queries, results mapped to handlebars UI components,
HTML streamed to client
## Validation
### When working on rust code
Mandatory formatting (rust): `cargo fmt --all`
Mandatory linting: `cargo clippy --all-targets --all-features -- -D warnings`
### When working on css or js
Frontend formatting: `npm run format`
More about testing: see [github actions](./.github/workflows/ci.yml).
Project structure: see [contribution guide](./CONTRIBUTING.md)
NEVER reformat/lint/touch files unrelated to your task. Always run tests/lints/format before stopping when you changed code.
### Testing
```
cargo test # tests with inmemory sqlite by default
```
For other databases, see [docker testing setup](./docker-compose.yml)
```
docker compose up -d mssql # or postgres or mysql
DATABASE_URL='mssql://root:Password123!@localhost/sqlpage' cargo test # all dbms use the same user:pass and db name
```
### Documentation
Components and functions are documented in [official website](./examples/official-site/sqlpage/migrations/); one migration per component and per function. You CAN update existing migrations, the official site database is recreated from scratch on each deployment.
official documentation website sql tables:
- `component(name,description,icon,introduced_in_version)` -- icon name from tabler icon
- `parameter(top_level BOOLEAN, name, component REFERENCES component(name), description, description_md, type, optional BOOLEAN)` parameter types: BOOLEAN, COLOR, HTML, ICON, INTEGER, JSON, REAL, TEXT, TIMESTAMP, URL
- `example(component REFERENCES component(name), description, properties JSON)`
#### Project Conventions
- Components: defined in `./sqlpage/templates/*.handlebars`
- Functions: `src/webserver/database/sqlpage_functions/functions.rs` registered with `make_function!`.
- [Configuration](./configuration.md): see [AppConfig](./src/app_config.rs)
- Routing: file-based in `src/webserver/routing.rs`; not found handled via `src/default_404.sql`.
- Follow patterns from similar modules before introducing new abstractions.
- frontend: see [css](./sqlpage/sqlpage.css) and [js](./sqlpage/sqlpage.js)