{"id":30880081,"url":"https://github.com/cloud-shuttle/leptos-query","last_synced_at":"2025-09-08T06:12:03.810Z","repository":{"id":312631961,"uuid":"1048129956","full_name":"cloud-shuttle/leptos-query","owner":"cloud-shuttle","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-01T02:11:13.000Z","size":294973,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-01T03:33:23.453Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloud-shuttle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-01T01:10:40.000Z","updated_at":"2025-09-01T02:11:16.000Z","dependencies_parsed_at":"2025-09-01T03:33:35.726Z","dependency_job_id":"f4939b92-1a7b-4cfc-8c62-fa6432bfdcac","html_url":"https://github.com/cloud-shuttle/leptos-query","commit_stats":null,"previous_names":["cloud-shuttle/leptos-query"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cloud-shuttle/leptos-query","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-shuttle%2Fleptos-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-shuttle%2Fleptos-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-shuttle%2Fleptos-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-shuttle%2Fleptos-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloud-shuttle","download_url":"https://codeload.github.com/cloud-shuttle/leptos-query/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-shuttle%2Fleptos-query/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274141013,"owners_count":25229149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-08T06:11:58.843Z","updated_at":"2025-09-08T06:12:03.794Z","avatar_url":"https://github.com/cloud-shuttle.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Leptos Query\n\nA React Query inspired data fetching library for Leptos applications, providing powerful caching, background updates, and error handling capabilities.\n\n**🚀 Now fully compatible with Leptos 0.8!**\n\n## Features\n\n- **Declarative Data Fetching**: Write queries as simple async functions\n- **Automatic Caching**: Built-in cache with configurable stale times\n- **Background Updates**: Keep data fresh with background refetching\n- **Error Handling**: Comprehensive error handling with retry logic\n- **Type Safety**: Full type safety with Rust's type system\n- **WASM Compatible**: Works in both native and web environments\n- **Leptos 0.8 Ready**: Full compatibility with the latest Leptos framework\n\n## Quick Start\n\n### Installation\n\nAdd to your `Cargo.toml`:\n\n```toml\n[dependencies]\nleptos-query = \"0.4.0\"\nleptos = \"0.8\"\nserde = { version = \"1.0\", features = [\"derive\"] }\n```\n\n### Basic Usage\n\n```rust\nuse leptos::*;\nuse leptos_query::*;\nuse serde::{Deserialize, Serialize};\n\n#[derive(Clone, Debug, Serialize, Deserialize)]\nstruct User {\n    id: u32,\n    name: String,\n    email: String,\n}\n\nasync fn fetch_user(id: u32) -\u003e Result\u003cUser, QueryError\u003e {\n    // Your async function here\n    Ok(User {\n        id,\n        name: \"John Doe\".to_string(),\n        email: \"john@example.com\".to_string(),\n    })\n}\n\n#[component]\nfn UserProfile(user_id: u32) -\u003e impl IntoView {\n    let user_query = use_query(\n        move || QueryKey::new(\u0026[\"user\", \u0026user_id.to_string()]),\n        move || async move { fetch_user(user_id).await },\n        QueryOptions::default(),\n    );\n\n    view! {\n        \u003cdiv\u003e\n            {move || match user_query.data.get() {\n                Some(user) =\u003e view! { \u003cdiv\u003e\"User: \" {user.name}\u003c/div\u003e },\n                None if user_query.is_loading.get() =\u003e view! { \u003cdiv\u003e\"Loading...\"\u003c/div\u003e },\n                None =\u003e view! { \u003cdiv\u003e\"No user found\"\u003c/div\u003e },\n            }}\n        \u003c/div\u003e\n    }\n}\n```\n\n### Setup\n\nWrap your app with the `QueryClientProvider`:\n\n```rust\n#[component]\nfn App() -\u003e impl IntoView {\n    view! {\n        \u003cQueryClientProvider\u003e\n            \u003cUserProfile user_id=1/\u003e\n        \u003c/QueryClientProvider\u003e\n    }\n}\n```\n\n## API Reference\n\n### Query Hook\n\n```rust\npub fn use_query\u003cT, F, Fut\u003e(\n    key_fn: F,\n    query_fn: impl Fn() -\u003e Fut + Clone + Send + Sync + 'static,\n    options: QueryOptions,\n) -\u003e QueryResult\u003cT\u003e\n```\n\n**Parameters:**\n- `key_fn`: Function that returns a `QueryKey` for caching\n- `query_fn`: Async function that fetches the data\n- `options`: Configuration options for the query\n\n**Returns:**\n- `QueryResult\u003cT\u003e`: Object containing data, loading state, and actions\n\n### Query Options\n\n```rust\nlet options = QueryOptions::default()\n    .with_stale_time(Duration::from_secs(60))\n    .with_cache_time(Duration::from_secs(300))\n    .with_refetch_interval(Duration::from_secs(30));\n```\n\n### Query Result\n\n```rust\npub struct QueryResult\u003cT\u003e {\n    pub data: Signal\u003cOption\u003cT\u003e\u003e,           // The query data\n    pub error: Signal\u003cOption\u003cQueryError\u003e\u003e, // Error if any\n    pub is_loading: Signal\u003cbool\u003e,          // Whether loading\n    pub is_success: Signal\u003cbool\u003e,          // Whether succeeded\n    pub is_error: Signal\u003cbool\u003e,            // Whether failed\n    pub status: Signal\u003cQueryStatus\u003e,       // Current status\n    pub refetch: Callback\u003c()\u003e,             // Refetch function\n}\n```\n\n### Mutation Hook\n\n```rust\npub fn use_mutation\u003cTData, TError, TVariables, F, Fut\u003e(\n    mutation_fn: F,\n    options: MutationOptions,\n) -\u003e MutationResult\u003cTData, TError, TVariables\u003e\n```\n\n**Example:**\n\n```rust\nasync fn create_user(user: CreateUserRequest) -\u003e Result\u003cUser, QueryError\u003e {\n    // Your mutation logic here\n    Ok(User { /* ... */ })\n}\n\nlet mutation = use_mutation(\n    create_user,\n    MutationOptions::default()\n        .invalidate_queries(vec![QueryKeyPattern::Exact(QueryKey::from(\"users\"))]),\n);\n\n// Execute mutation\nmutation.mutate.call(CreateUserRequest { /* ... */ });\n```\n\n### Error Handling\n\nThe library provides comprehensive error handling:\n\n```rust\n#[derive(Debug, Clone, Serialize, Deserialize)]\npub enum QueryError {\n    NetworkError(String),\n    SerializationError(String),\n    DeserializationError(String),\n    TimeoutError(String),\n    GenericError(String),\n}\n```\n\n### Retry Configuration\n\n```rust\nlet retry_config = RetryConfig::new(3, Duration::from_secs(1))\n    .with_max_delay(Duration::from_secs(30))\n    .with_fixed_delay()\n    .no_network_retry();\n```\n\n## Advanced Features\n\n### Query Keys\n\nQuery keys are used for caching and invalidation:\n\n```rust\n// Simple key\nQueryKey::from(\"users\")\n\n// Compound key\nQueryKey::from([\"users\", user_id.to_string()])\n\n// With parameters\nQueryKey::from_parts(\u0026[user_id, filter]).unwrap()\n```\n\n### Cache Invalidation\n\n```rust\n// Invalidate specific queries\nclient.remove_query(\u0026QueryKey::from(\"users\"));\n\n// Invalidate by pattern\nclient.invalidate_queries(\u0026QueryKeyPattern::Prefix(QueryKey::from(\"users\")));\n```\n\n### Background Refetching\n\n```rust\nlet options = QueryOptions::default()\n    .with_refetch_interval(Duration::from_secs(30));\n```\n\n## Examples\n\nSee the `examples/` directory for complete working examples:\n\n- `basic.rs`: Basic query usage\n- `mutations.rs`: Mutation examples\n- `caching.rs`: Advanced caching examples\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud-shuttle%2Fleptos-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloud-shuttle%2Fleptos-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud-shuttle%2Fleptos-query/lists"}