| Crates.io | akita_codegen |
| lib.rs | akita_codegen |
| version | 0.6.0 |
| created_at | 2026-01-08 03:58:02.048653+00 |
| updated_at | 2026-01-08 03:58:02.048653+00 |
| description | Akita - Mini orm for rust. |
| homepage | https://github.com/wslongchen/akita |
| repository | https://github.com/wslongchen/akita |
| max_upload_size | |
| id | 2029506 |
| size | 190,878 |
Akita CodeGen is a powerful Rust-based code generation tool specifically designed for the Akita framework to generate CRUD (Create, Read, Update, Delete) related code. By connecting to databases and analyzing table structures, it automatically generates entity classes, service layers, data access layers, controllers, and more, significantly improving development efficiency.
# Clone repository
git clone <repository-url>
# Build project
cargo build --release
# Install locally
cargo install --path .
cargo install akita_codegen
# Generate code with default configuration
akita_codegen
# Specify configuration file
akita_codegen -c config.yaml
If run for the first time without a configuration file, the tool enters interactive configuration mode:
$ akita_codegen
Would you like to set up the configuration interactively?
[Y/n]: Y
Enter your table_names (like 'table_a,table_b')
: user,product,order
Enter your database URL
: mysql://username:password@localhost:3306/mydatabase
Enter your template directory path
: ./templates
Enter your output directory path
: ./src/generated
Create a config.yaml file:
global:
output_dir: ./src/generated
template_dir: ./templates/*
file_override: true
author: YourName
entity_name: "%sEntity"
service_name: "%sService"
service_impl_name: "%sServiceImpl"
mapper_name: "%sMapper"
controller_name: "%sController"
package:
parent: com.example.project
module_name: demo
entity: domain.entity
service: domain.service
service_impl: domain.service.impl
mapper: infrastructure.mapper
controller: application.controller
strategy:
capital_mode: false
naming: UnderlineToCamel
column_naming: NoChange
table_prefix: ["tbl_", "sys_"]
include:
- user
- product
- order
exclude:
- audit_log
datasource:
driver_name: "com.mysql.cj.jdbc.Driver"
username: root
password: your_password
url: mysql://username:password@localhost:3306/your_database?useSSL=false&serverTimezone=UTC
db_type: Mysql
template:
entity: ./templates/entity.rs
service: ./templates/service.rs
service_impl: ./templates/service_impl.rs
controller: ./templates/controller.rs
mapper: ./templates/mapper.rs
plugins: []
| Field | Type | Default | Description |
|---|---|---|---|
output_dir |
String | "" |
Code output directory |
template_dir |
String | ./templates |
Template file directory |
file_override |
bool | true |
Whether to override existing files |
active_record |
bool | false |
Whether to enable ActiveRecord mode |
open |
bool | false |
Whether to automatically open directory after generation |
author |
String | "" |
Author information |
service_name |
String | "" |
Service class naming template (%s as placeholder) |
entity_name |
String | "" |
Entity class naming template |
service_impl_name |
String | "" |
Service implementation class naming template |
mapper_name |
String | "" |
Mapper class naming template |
controller_name |
String | "" |
Controller class naming template |
| Field | Type | Default | Description |
|---|---|---|---|
parent |
String | "com.snack" |
Parent package name |
module_name |
String | "" |
Module name |
entity |
String | "entity" |
Entity class package name |
service |
String | "service" |
Service interface package name |
service_impl |
String | "service.impl" |
Service implementation package name |
mapper |
String | "mapper" |
Data access layer package name |
controller |
String | "controller" |
Controller package name |
| Field | Type | Default | Description |
|---|---|---|---|
capital_mode |
bool | false |
Global uppercase naming mode |
naming |
NamingStrategy | UnderlineToCamel |
Table naming strategy |
column_naming |
Option |
NoChange |
Column naming strategy |
entity_boolean_column_remove_is_prefix |
bool | false |
Whether to remove 'is' prefix from boolean fields |
table_prefix |
Vec |
[] |
Table prefixes to remove |
field_prefix |
Vec |
[] |
Field prefixes to remove |
include |
Vec |
[] |
List of tables to include |
exclude |
Vec |
[] |
List of tables to exclude |
skip_view |
bool | false |
Whether to skip view tables |
| Field | Type | Default | Description |
|---|---|---|---|
driver_name |
String | "" |
Database driver class name |
username |
String | "" |
Database username |
password |
String | "" |
Database password |
url |
String | "" |
Database connection URL |
db_type |
DbType | Mysql |
Database type (currently supports Mysql) |
UnderlineToCamel: Snake case to camelCase (e.g., user_name → userName)CamelToUnderline: CamelCase to snake_case (e.g., userName → user_name)NoChange: Keep original formattemplates/
├── entity.rs # Entity class template
├── service.rs # Service interface template
├── serviceImpl.rs # Service implementation template
├── controller.rs # Controller template
└── mapper.rs # Data access layer template
The following variables are available in template files:
{{package}}: Package name{{imports}}: Import statements{{className}}: Class name{{tableName}}: Table name{{fields}}: Field list{{author}}: Author{{date}}: Generation dateCreate custom template files:
// templates/custom_entity.rs
/**
* {{tableName}} Entity
*
* @author {{author}}
* @date {{date}}
*/
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct {{ entity }} {
{%- for field in table.fields %}
{%- if field.comment != "" %}
/// {{ field.comment }}
{% else %}
{% endif -%}
pub {{field.propertyName}}: Option<{{field.columnType}}>,
{%- endfor %}
}
strategy:
include:
- user
- product
- order_item
- category
exclude:
- system_config
strategy:
table_prefix:
- "tbl_"
- "sys_"
include:
- tbl_user
- sys_log
strategy:
table_fill_list:
- field_name: create_time
field_fill: Insert
- field_name: update_time
field_fill: InsertUpdate
strategy:
super_entity_class: "com.example.base.BaseEntity"
super_service_class: "com.example.base.BaseService"
super_service_impl_class: "com.example.base.BaseServiceImpl"
super_mapper_class: "com.example.base.BaseMapper"
super_controller_class: "com.example.base.BaseController"
# Show help information
akita_codegen --help
# Show version information
akita_codegen --version
# Specify configuration file
akita_codegen --config custom-config.yaml
# Use short arguments
akita_codegen -c config.yaml
Problem: Unable to connect to database
Solution:
mysql://username:password@host:port/databaseProblem: Template files not found
Solution:
template_dir configuration is correctProblem: Generated code format doesn't match expectations
Solution:
Problem: Unable to read database table structure
Solution:
Create plugins by implementing the Plugin trait:
pub trait Plugin {
fn name(&self) -> &str;
fn execute(&self, context: &mut CodeGenContext) -> Result<(), Box<dyn Error>>;
}
Implement CodeGenerationStrategy trait for custom code generation logic:
pub trait CodeGenerationStrategy {
fn generate_entity(&self, table: &TableInfo) -> Result<String>;
fn generate_service(&self, table: &TableInfo) -> Result<String>;
fn generate_mapper(&self, table: &TableInfo) -> Result<String>;
fn generate_controller(&self, table: &TableInfo) -> Result<String>;
}
Contributions are welcome! Please follow these steps:
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)This project is licensed under the MIT License.
Note: Code generated by this tool is for reference only. Please adjust and optimize according to your project requirements.