{"id":22169741,"url":"https://github.com/thegenius/luna-orm","last_synced_at":"2025-07-26T13:32:39.415Z","repository":{"id":209755499,"uuid":"724877899","full_name":"thegenius/luna-orm","owner":"thegenius","description":"A simple orm to saving lives","archived":false,"fork":false,"pushed_at":"2024-03-15T08:19:32.000Z","size":5423,"stargazers_count":28,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-03-15T09:36:47.724Z","etag":null,"topics":["orm","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thegenius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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}},"created_at":"2023-11-29T01:12:31.000Z","updated_at":"2024-05-22T13:30:43.915Z","dependencies_parsed_at":"2024-01-23T03:29:51.868Z","dependency_job_id":"af7b9627-c271-4e31-87cf-3af24c813ed0","html_url":"https://github.com/thegenius/luna-orm","commit_stats":null,"previous_names":["thegenius/luna-orm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thegenius%2Fluna-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thegenius%2Fluna-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thegenius%2Fluna-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thegenius%2Fluna-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thegenius","download_url":"https://codeload.github.com/thegenius/luna-orm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227543145,"owners_count":17785195,"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","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":["orm","rust"],"created_at":"2024-12-02T06:34:41.340Z","updated_at":"2024-12-02T06:34:42.420Z","avatar_url":"https://github.com/thegenius.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# :warning: LUNA-ORM is under rapid development, api may change, you should not use it in PRODUCTION env.\nFor now, just have a basic taste, waiting for the version 1.0  \nAt that time, the api will be stable, and backward compatible will be promised.  \n\n  \n![Building](https://github.com/thegenius/luna-orm/actions/workflows/rust.yml/badge.svg)\n[![Version](https://img.shields.io/badge/crates-0.3.6-green)](https://crates.io/crates/luna-orm)\n\n# LUNA-ORM\n\n**LUNA-ORM** is an async orm framework based on SQLx. Built with :heart:\n-  **Intuitive** : Simple API, the most simple orm in this world.\n-  **Time Saving** : Most useful API is implemented by default, no need to waste your life.\n-  **Smooth Transaction** : Transaction is almost same as normal.\n-  **Template SQL** : You can execute your own sql with no pain.\n-  **Dynamic Parameters** : Handle complex dynamic sql with default.\n-  **Truly Asynchronous** : Based on SQLx, luna-orm is fully async.\n-  **Error Soundly** : Every error has its meaning. \n\n## ROADMAP\n- **0.1 API Skeleton** :white_check_mark:\n- **0.2 Transaction** transaction support :white_check_mark:\n- **0.3 Static Template** static tempalte sql and tracing  :white_check_mark:\n- **0.4 Relationship**: support relationship :hammer: (I'm working hard on this, and finally maybe something like the core part of GraphQL)\n- **0.5 Dynamic Template**: support dynamic template :pushpin:\n- **0.6 Error**: :pushpin:\n- **0.7 Performance**: benchmark and optimize :pushpin:\n- **0.7 Correctness**: code coverage and mocking :pushpin:\n- **0.9 Stablization and Doc**: stablize the api, macro and error :pushpin:\n- **1.0 Fisrt stable version**: :pushpin:\n- **2.0 Ecosystem**: :paperclip:\n\n## INSTALL\n```toml\nluna-orm = { version = \"0.3.6\" }\n  \n```\n\n## Intuitive\nEverything should just works as you want.\n\n\n### Create a database instance.\n```rust\nuse luna_orm::prelude::*;\nuse luna_orm::LunaOrmResult;\n\n#[tokio::main]\npub async fn main() -\u003e LunaOrmResult\u003c()\u003e {\n\n  // 1. example use sqlite with local file mode\n  let config = SqliteLocalConfig::new(\"./workspace\", \"test.db\");\n\n  // 2. create a DB instance.\n  let mut db: DB\u003cSqliteDatabase\u003e = SqliteDatabase::build(config).await.unwrap().into();\n\n  // optional: you may need to create the table for the first time.\n  // db.execute_plain(\n  //      \"CREATE TABLE IF NOT EXISTS `user`(`id` INT PRIMARY KEY, `age` INT, `name` VARCHAR(64))\",\n  // )\n  \n  Ok(())\n}\n \n```\n### Insert an entity\n\n```rust\n// 1. Declare an Entity, Derive macro Entity, give a TableName\n#[derive(Entity, Clone, Debug)]\n#[TableName = \"user\"]\npub struct HelloEntity {\n    #[PrimaryKey]\n    id: i32,\n    name: String,\n    age: Option\u003ci32\u003e,\n}\n\n\n// 2. create an entity.\nlet entity = HelloEntity {\n      id: 1,\n      name: \"Allen\".to_string(),\n      age: Some(23)\n}; \n// 3. insert it, this is so intuitive, you don't need to warry about anything, it jsut works.\nlet result = db.insert(\u0026entity).await?;\n```\n\n## Time Saving\nAlmost 90% command has been implemented by default, this may saving your time.i\n\n## Concept\n![](https://github.com/thegenius/luna-orm/blob/main/docs/concept.png)\n\n### If you want to insert\n```rust\n  // insert an entity if not exists.\n  async fn insert(\u0026mut self, entity: \u0026dyn Entity) -\u003e LunaOrmResult\u003cbool\u003e;\n  \n  // insert is not exists, and update if already exists.\n  async fn upsert(\u0026mut self, entity: \u0026dyn Entity) -\u003e LunaOrmResult\u003cbool\u003e;\n\n  // insert an entity if not exists, and return the inserted entity.\n  async fn create\u003c'a\u003e(\u0026mut self, entity: \u0026'a dyn Entity) -\u003e LunaOrmResult\u003c\u0026'a dyn Entity\u003e;\n```\n### If you want to update\n```rust\n  // update one record by primary\n  async fn update(\u0026mut self, mutation: \u0026dyn Mutation, primary: \u0026dyn Primary) -\u003e LunaOrmResult\u003cbool\u003e \n\n  // update many records by location\n  async fn change(\u0026mut self,mutation: \u0026dyn Mutation, location: \u0026dyn Location) -\u003e LunaOrmResult\u003cusize\u003e;\n  \n```\n\n\n### If you want to delete\n```rust\n\n  // delete one record by primary\n  async fn delete(\u0026mut self, primary: \u0026dyn Primary) -\u003e LunaOrmResult\u003cbool\u003e;\n\n  // delete many records by location\n  async fn purify(\u0026mut self, location: \u0026dyn Location) -\u003e LunaOrmResult\u003cusize\u003e;\n  \n```\n\n### If you want to select\n```rust\n  // fetch one entity by primary and select fields by selection \n  async fn select\u003cSE\u003e(\n    \u0026mut self, \n    primary: \u0026dyn Primary, \n    selection: \u0026dyn Selection\n  ) -\u003e LunaOrmResult\u003cOption\u003cSE\u003e\u003e\n     where\n        SE: SelectedEntity + Send + Unpin; \n\n  // fetch many entity by location\u0026order and select fields by selection\n   async fn search\u003cSE\u003e(\n        \u0026mut self,\n        location: \u0026dyn Location,\n        order_by: Option\u003c\u0026dyn OrderBy\u003e,\n        selection: \u0026dyn Selection,\n    ) -\u003e LunaOrmResult\u003cVec\u003cSE\u003e\u003e\n    where\n        SE: SelectedEntity + Send + Unpin;\n\n  // fetch paged entity with pagination\n   async fn search_paged\u003cSE\u003e(\n        \u0026mut self,\n        location: \u0026dyn Location,\n        order_by: Option\u003c\u0026dyn OrderBy\u003e,\n        selection: \u0026dyn Selection,\n        page: \u0026Pagination,\n    ) -\u003e LunaOrmResult\u003cPagedList\u003cSE\u003e\u003e\n    where\n        SE: SelectedEntity + Send + Unpin;\n        \n```\n\n\n\n\n## Smooth Transaction\n```rust\n  let db: DB\u003cSqliteDatabase\u003e = SqliteDatabase::build(config).await.unwrap().into();\n  // 1. start a transaction by the simple async api.\n  let mut trx = db.transaction().await.unwrap();\n\n  // 2. just do every thing you want,\n  // every command is just same as normal.  \n  trx.insert(...).await?;\n  trx.select(...).await?;\n  trx.delete(...).await?;\n\n  // 3. last thing is just commit, if you forget, trx will rollback by default. \n  trx.commit().await?;\n  \n```\n\n## Template SQL\n```rust\n#[derive(TemplateRecord)]\n#[TemplateSql = \"update article set content = #{content} where id = #{id}\"]\npub struct HelloTemplate {\n    id: i32,\n    content: String,\n}\n\n#[derive(TemplateRecord)]\n#[TemplateSql = \"select * FROM article where id \u003e #{id}\"]\n#[TemplateCountSql = \"select count(*) as count FROM article where id \u003e #{id}\"]\npub struct HelloSelectTemplate {\n    id: i32,\n}\n\nlet template = HelloTemplate {\n    id: 2,\n    content: \"template\".to_string(),\n};\n// template just works as you want, #{} is the variable \ndb.execute_by_template(\u0026template).await?;\n\n\n// if you want to execute paged template,\n// you should give a TemplateCountSql, the `as count` is important.\nlet select_template = HelloSelectTemplate { id: 0 };\nlet page = Pagination {\n        page_size: 1,\n        page_num: 1,\n};\nlet result: PagedList\u003cHelloSelectedEntity\u003e =\n    db.search_paged_by_template(\u0026select_template, \u0026page).await?;\n\n\n  \n```\n\n## Dynamic Parameters\n\n## Truly Asynchronous\n\n## Error Sound\n\n\n## MSRV: Minimum Supported Rust Version\n1.75.0  \nLUNA-ORM use async trait.\n\n## Safety\nThis lib uses #![forbid(unsafe_code)]\n\n## LICENSE\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthegenius%2Fluna-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthegenius%2Fluna-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthegenius%2Fluna-orm/lists"}