|
| 1 | +use super::{ |
| 2 | + Seed, |
| 3 | + content::{Parameter, pages}, |
| 4 | +}; |
| 5 | +use anyhow::Result; |
| 6 | +use serde::Deserialize; |
| 7 | +use std::path::Path; |
| 8 | + |
| 9 | +#[derive(Default, Deserialize)] |
| 10 | +#[serde(deny_unknown_fields)] |
| 11 | +struct Function { |
| 12 | + icon: Option<String>, |
| 13 | + since: Option<String>, |
| 14 | + category: Option<String>, |
| 15 | + summary: Option<String>, |
| 16 | + return_type: Option<String>, |
| 17 | + #[serde(default)] |
| 18 | + parameters: Vec<Parameter>, |
| 19 | +} |
| 20 | + |
| 21 | +pub(super) fn insert(seed: &mut Seed, dir: &Path) -> Result<()> { |
| 22 | + pages(dir, |name, f: Function, body| { |
| 23 | + seed.row( |
| 24 | + "INSERT INTO sqlpage_functions (name, icon, description_md, return_type, |
| 25 | + introduced_in_version, catalog_category, catalog_summary) VALUES (?, ?, ?, ?, ?, ?, ?)", |
| 26 | + &[&name, &f.icon, &body, &f.return_type, &f.since, &f.category, &f.summary], |
| 27 | + )?; |
| 28 | + for (index, p) in (1_i64..).zip(f.parameters) { |
| 29 | + p.validate()?; |
| 30 | + seed.row( |
| 31 | + "INSERT INTO sqlpage_function_parameters (\"function\", \"index\", name, description_md, type, optional) |
| 32 | + VALUES (?, ?, ?, ?, ?, ?)", |
| 33 | + &[&name, &index, &p.name, &p.description, &p.r#type, &!p.required], |
| 34 | + )?; |
| 35 | + } |
| 36 | + Ok(()) |
| 37 | + }) |
| 38 | +} |
0 commit comments