rjango 0.1.1

A full-stack Rust backend framework inspired by Django
Documentation
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DatabaseFeatures {
    pub supports_transactions: bool,
    pub supports_savepoints: bool,
    pub supports_partial_indexes: bool,
    pub supports_json_field: bool,
    pub supports_foreign_keys: bool,
    pub supports_check_constraints: bool,
    pub supports_sequence_reset: bool,
    pub can_introspect_json_field: bool,
    pub has_bulk_insert: bool,
    pub supports_tablespaces: bool,
    pub supports_column_check_constraints: bool,
    pub supports_expression_indexes: bool,
    pub uses_savepoints: bool,
}

impl DatabaseFeatures {
    #[must_use]
    pub fn sqlite() -> Self {
        Self {
            supports_transactions: true,
            supports_savepoints: true,
            supports_partial_indexes: true,
            supports_json_field: true,
            supports_foreign_keys: true,
            supports_check_constraints: true,
            supports_sequence_reset: true,
            can_introspect_json_field: false,
            has_bulk_insert: true,
            supports_tablespaces: false,
            supports_column_check_constraints: false,
            supports_expression_indexes: true,
            uses_savepoints: true,
        }
    }

    #[must_use]
    pub fn postgresql() -> Self {
        Self {
            supports_transactions: true,
            supports_savepoints: true,
            supports_partial_indexes: true,
            supports_json_field: true,
            supports_foreign_keys: true,
            supports_check_constraints: true,
            supports_sequence_reset: true,
            can_introspect_json_field: true,
            has_bulk_insert: true,
            supports_tablespaces: true,
            supports_column_check_constraints: true,
            supports_expression_indexes: true,
            uses_savepoints: true,
        }
    }

    #[must_use]
    pub fn mysql() -> Self {
        Self {
            supports_transactions: true,
            supports_savepoints: true,
            supports_partial_indexes: false,
            supports_json_field: true,
            supports_foreign_keys: true,
            supports_check_constraints: true,
            supports_sequence_reset: true,
            can_introspect_json_field: true,
            has_bulk_insert: true,
            supports_tablespaces: true,
            supports_column_check_constraints: true,
            supports_expression_indexes: true,
            uses_savepoints: true,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::DatabaseFeatures;

    #[test]
    fn sqlite_features_match_expected_capabilities() {
        let features = DatabaseFeatures::sqlite();

        assert!(features.supports_transactions);
        assert!(features.supports_partial_indexes);
        assert!(features.supports_expression_indexes);
        assert!(!features.supports_tablespaces);
        assert!(!features.can_introspect_json_field);
        assert!(!features.supports_column_check_constraints);
    }

    #[test]
    fn postgresql_features_match_expected_capabilities() {
        let features = DatabaseFeatures::postgresql();

        assert!(features.supports_transactions);
        assert!(features.supports_savepoints);
        assert!(features.supports_partial_indexes);
        assert!(features.supports_tablespaces);
        assert!(features.can_introspect_json_field);
        assert!(features.supports_expression_indexes);
    }

    #[test]
    fn mysql_features_match_expected_capabilities() {
        let features = DatabaseFeatures::mysql();

        assert!(features.supports_transactions);
        assert!(features.supports_savepoints);
        assert!(!features.supports_partial_indexes);
        assert!(features.supports_json_field);
        assert!(features.supports_tablespaces);
        assert!(features.supports_column_check_constraints);
    }

    #[test]
    fn backend_feature_profiles_differ_where_expected() {
        let sqlite = DatabaseFeatures::sqlite();
        let postgres = DatabaseFeatures::postgresql();
        let mysql = DatabaseFeatures::mysql();

        assert_ne!(sqlite, postgres);
        assert_ne!(sqlite, mysql);
        assert_ne!(
            postgres.supports_partial_indexes,
            mysql.supports_partial_indexes
        );
    }
}