Skip to main content

rbatis_plus_sqlparser/dialect/
mysql.rs

1//! MySQL 方言(对标 mybatis-plus `MySqlDialect`)。
2//!
3//! 分页语法: `LIMIT offset, size`
4
5use super::SqlDialect;
6
7/// MySQL 分页方言。
8///
9/// 对应 Java `com.baomidou.mybatisplus.extension.plugins.pagination.dialects.MySqlDialect`
10#[derive(Debug)]
11pub struct MysqlDialect;
12
13impl SqlDialect for MysqlDialect {
14    fn name(&self) -> &str {
15        "MySQL"
16    }
17
18    /// MySQL 分页: `SELECT ... LIMIT offset, size`
19    fn build_pagination_sql(&self, sql: &str, offset: u64, size: u64) -> String {
20        format!("{} LIMIT {}, {}", sql.trim_end(), offset, size)
21    }
22
23    fn supports(&self, db_type: &str) -> bool {
24        let lower = db_type.to_lowercase();
25        lower.contains("mysql") || lower.contains("mariadb")
26    }
27}