CodeBench: --compact tiivistää golden examplen templaatiksi
Python: 1340 → 335 tokenia (−75%) Rust: 3383 → 445 tokenia (−87%) Käyttö: node benchmark.mjs --compact --models qwen3:4b
This commit is contained in:
43
kipina-codebench/prompts/golden-compact-rs.md
Normal file
43
kipina-codebench/prompts/golden-compact-rs.md
Normal file
@@ -0,0 +1,43 @@
|
||||
REFERENCE PATTERNS (follow exactly):
|
||||
|
||||
STACK: Axum 0.8 + SQLx + SQLite + Tokio + Serde
|
||||
|
||||
Cargo.toml:
|
||||
edition = "2024"
|
||||
deps: axum 0.8, tokio (full), serde (derive), serde_json, sqlx (sqlite, runtime-tokio), tower-http (cors)
|
||||
dev: reqwest (rustls-tls)
|
||||
|
||||
src/models.rs:
|
||||
#[derive(Debug, Serialize, Deserialize, FromRow)]
|
||||
struct Entity { id: i64, field: String, optional: Option<String> }
|
||||
struct CreateEntity { field: String, optional: Option<String> }
|
||||
Status fields: String with default "pending"
|
||||
|
||||
src/handlers.rs:
|
||||
async fn create(State(pool), Json(input)) -> (StatusCode, Json<Entity>)
|
||||
POST → StatusCode::CREATED, sqlx::query("INSERT...").execute + query_as last_insert_rowid
|
||||
GET list → query_as("SELECT * FROM table").fetch_all
|
||||
GET by id → query_as.fetch_optional, return 404 if None
|
||||
PUT → query("UPDATE...SET...WHERE id=?"), rows_affected == 0 → 404
|
||||
DELETE → StatusCode::NO_CONTENT, rows_affected == 0 → 404
|
||||
|
||||
src/lib.rs:
|
||||
pub fn app(pool: SqlitePool) -> Router
|
||||
pub async fn init_db(pool: &SqlitePool) → CREATE TABLE IF NOT EXISTS
|
||||
Routes: .route("/{table}", post(create).get(list))
|
||||
.route("/{table}/:id", get(get_one).put(update).delete(delete_one))
|
||||
|
||||
src/main.rs:
|
||||
SqlitePool::connect("sqlite:./app.db"), init_db, bind 0.0.0.0:3000
|
||||
|
||||
tests/api_test.rs:
|
||||
Each test: SqlitePool::connect("sqlite::memory:"), init_db, app(pool)
|
||||
Spawn on random port: TcpListener::bind("127.0.0.1:0"), axum::serve
|
||||
reqwest::Client for HTTP calls
|
||||
Unique Finnish data ("Osta maitoa", "Haettava tehtävä"...)
|
||||
test_create → 201 + assert id exists
|
||||
test_list → post first, get, assert len >= 1
|
||||
test_get_by_id → post, get, assert id matches
|
||||
test_not_found → 404
|
||||
test_update → post, put with ALL fields, assert 200
|
||||
test_delete → post, delete 204, get → 404
|
||||
Reference in New Issue
Block a user