hydracache-db 0.58.0

Database-neutral query result cache adapter for HydraCache.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
use std::fmt;

use thiserror::Error;

pub const HOOK_SCHEMA_ARTIFACT: &str = "hydracache_hook_schema";
pub const HOOK_SCHEMA_VERSION: i64 = 1;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HookDialect {
    Postgres,
    MySql,
    Sqlite,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HookOperation {
    Insert,
    Update,
    Delete,
}

impl HookOperation {
    fn as_str(self) -> &'static str {
        match self {
            Self::Insert => "insert",
            Self::Update => "update",
            Self::Delete => "delete",
        }
    }

    fn sqlite_row_ref(self) -> &'static str {
        match self {
            Self::Insert | Self::Update => "NEW",
            Self::Delete => "OLD",
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HookInvalidationTarget {
    KeyColumn { column: String },
    Tag { tag: String },
    TagColumn { prefix: String, column: String },
    Entity { entity: String, key_column: String },
    Collection { collection: String },
}

impl HookInvalidationTarget {
    pub fn key_column(column: impl Into<String>) -> Self {
        Self::KeyColumn {
            column: column.into(),
        }
    }

    pub fn tag(tag: impl Into<String>) -> Self {
        Self::Tag { tag: tag.into() }
    }

    pub fn tag_column(prefix: impl Into<String>, column: impl Into<String>) -> Self {
        Self::TagColumn {
            prefix: prefix.into(),
            column: column.into(),
        }
    }

    pub fn entity(entity: impl Into<String>, key_column: impl Into<String>) -> Self {
        Self::Entity {
            entity: entity.into(),
            key_column: key_column.into(),
        }
    }

    pub fn collection(collection: impl Into<String>) -> Self {
        Self::Collection {
            collection: collection.into(),
        }
    }

    fn validate(&self) -> Result<(), HookError> {
        match self {
            Self::KeyColumn { column } if column.trim().is_empty() => {
                Err(HookError::MissingColumn("key".to_owned()))
            }
            Self::TagColumn { prefix, column } => {
                if prefix.trim().is_empty() {
                    return Err(HookError::MissingLiteral("tag prefix".to_owned()));
                }
                if column.trim().is_empty() {
                    return Err(HookError::MissingColumn("tag".to_owned()));
                }
                Ok(())
            }
            Self::Entity { entity, key_column } => {
                if entity.trim().is_empty() {
                    return Err(HookError::MissingLiteral("entity".to_owned()));
                }
                if key_column.trim().is_empty() {
                    return Err(HookError::MissingColumn("entity key".to_owned()));
                }
                Ok(())
            }
            Self::Tag { tag } if tag.trim().is_empty() => {
                Err(HookError::MissingLiteral("tag".to_owned()))
            }
            Self::Collection { collection } if collection.trim().is_empty() => {
                Err(HookError::MissingLiteral("collection".to_owned()))
            }
            _ => Ok(()),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HookOp {
    operation: HookOperation,
    target: HookInvalidationTarget,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HookSchemaVersion {
    pub artifact: String,
    pub version: i64,
    pub table: String,
    pub dialect: HookDialect,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HookPlan {
    dialect: HookDialect,
    table: String,
    namespace: String,
    ops: Vec<HookOp>,
}

impl HookPlan {
    pub fn sqlite(table: &str) -> Self {
        Self::new(HookDialect::Sqlite, table)
    }

    pub fn postgres(table: &str) -> Self {
        Self::new(HookDialect::Postgres, table)
    }

    pub fn mysql(table: &str) -> Self {
        Self::new(HookDialect::MySql, table)
    }

    pub fn new(dialect: HookDialect, table: &str) -> Self {
        Self {
            dialect,
            table: table.to_owned(),
            namespace: "db".to_owned(),
            ops: Vec::new(),
        }
    }

    pub fn namespace(mut self, namespace: impl Into<String>) -> Self {
        self.namespace = namespace.into();
        self
    }

    pub fn on_insert(self, target: HookInvalidationTarget) -> Self {
        self.on(HookOperation::Insert, target)
    }

    pub fn on_update(self, target: HookInvalidationTarget) -> Self {
        self.on(HookOperation::Update, target)
    }

    pub fn on_delete(self, target: HookInvalidationTarget) -> Self {
        self.on(HookOperation::Delete, target)
    }

    pub fn on(mut self, operation: HookOperation, target: HookInvalidationTarget) -> Self {
        self.ops.push(HookOp { operation, target });
        self
    }

    pub fn schema_version(&self) -> HookSchemaVersion {
        HookSchemaVersion {
            artifact: HOOK_SCHEMA_ARTIFACT.to_owned(),
            version: HOOK_SCHEMA_VERSION,
            table: self.table.clone(),
            dialect: self.dialect,
        }
    }

    pub fn render_sql(&self) -> Result<String, HookError> {
        Ok(self.render_statements()?.join("\n\n"))
    }

    pub fn render_statements(&self) -> Result<Vec<String>, HookError> {
        self.validate()?;
        match self.dialect {
            HookDialect::Sqlite => self.render_sqlite(),
            HookDialect::Postgres => self.render_postgres(),
            HookDialect::MySql => self.render_mysql(),
        }
    }

    #[cfg(feature = "sqlx-outbox")]
    pub async fn install_sqlite(&self, pool: &sqlx::SqlitePool) -> crate::Result<()> {
        for statement in self.render_statements()? {
            sqlx::query(&statement)
                .execute(pool)
                .await
                .map_err(|error| {
                    crate::DbCacheError::from(hydracache::CacheError::Backend(format!(
                        "sqlite hook install error: {error}"
                    )))
                })?;
        }
        Ok(())
    }

    fn validate(&self) -> Result<(), HookError> {
        validate_identifier(&self.table)?;
        if self.namespace.trim().is_empty() {
            return Err(HookError::MissingLiteral("namespace".to_owned()));
        }
        if self.ops.is_empty() {
            return Err(HookError::NoOperations);
        }
        for op in &self.ops {
            op.target.validate()?;
        }
        Ok(())
    }

    fn render_sqlite(&self) -> Result<Vec<String>, HookError> {
        let mut statements = hook_schema_statements_sqlite(&self.table);
        for operation in [
            HookOperation::Insert,
            HookOperation::Update,
            HookOperation::Delete,
        ] {
            let targets: Vec<_> = self
                .ops
                .iter()
                .filter(|op| op.operation == operation)
                .map(|op| &op.target)
                .collect();
            if targets.is_empty() {
                continue;
            }

            let trigger_name = format!("hydracache_{}_{}_outbox", self.table, operation.as_str());
            let mut body = String::new();
            for target in targets {
                body.push_str(&render_sqlite_insert(
                    &self.namespace,
                    &self.table,
                    operation,
                    target,
                )?);
                body.push('\n');
            }
            statements.push(format!(
                "create trigger if not exists {trigger_name}\nafter {} on {}\nbegin\n{}end;",
                operation.as_str(),
                self.table,
                body
            ));
        }
        Ok(statements)
    }

    fn render_postgres(&self) -> Result<Vec<String>, HookError> {
        let mut statements = hook_schema_statements_postgres(&self.table);
        for operation in [
            HookOperation::Insert,
            HookOperation::Update,
            HookOperation::Delete,
        ] {
            let targets: Vec<_> = self
                .ops
                .iter()
                .filter(|op| op.operation == operation)
                .map(|op| &op.target)
                .collect();
            if targets.is_empty() {
                continue;
            }
            let function_name =
                format!("hydracache_{}_{}_outbox_fn", self.table, operation.as_str());
            let trigger_name = format!("hydracache_{}_{}_outbox", self.table, operation.as_str());
            let mut body = String::new();
            for target in targets {
                body.push_str(&render_postgres_insert(
                    &self.namespace,
                    &self.table,
                    operation,
                    target,
                )?);
                body.push('\n');
            }
            statements.push(format!(
                "create or replace function {function_name}() returns trigger as $$\nbegin\n{}return {};\nend;\n$$ language plpgsql;",
                body,
                operation.sqlite_row_ref()
            ));
            statements.push(format!(
                "drop trigger if exists {trigger_name} on {};\ncreate trigger {trigger_name}\nafter {} on {}\nfor each row execute function {function_name}();",
                self.table,
                operation.as_str(),
                self.table
            ));
        }
        Ok(statements)
    }

    fn render_mysql(&self) -> Result<Vec<String>, HookError> {
        let mut statements = hook_schema_statements_mysql(&self.table);
        for operation in [
            HookOperation::Insert,
            HookOperation::Update,
            HookOperation::Delete,
        ] {
            let targets: Vec<_> = self
                .ops
                .iter()
                .filter(|op| op.operation == operation)
                .map(|op| &op.target)
                .collect();
            if targets.is_empty() {
                continue;
            }
            let trigger_name = format!("hydracache_{}_{}_outbox", self.table, operation.as_str());
            let mut body = String::new();
            for target in targets {
                body.push_str(&render_mysql_insert(
                    &self.namespace,
                    &self.table,
                    operation,
                    target,
                )?);
                body.push('\n');
            }
            statements.push(format!(
                "drop trigger if exists {trigger_name};\ncreate trigger {trigger_name}\nafter {} on {}\nfor each row\nbegin\n{}end;",
                operation.as_str(),
                self.table,
                body
            ));
        }
        Ok(statements)
    }
}

#[derive(Debug, Error)]
pub enum HookError {
    #[error("hook plan requires at least one operation")]
    NoOperations,
    #[error("invalid SQL identifier `{0}`")]
    InvalidIdentifier(String),
    #[error("hook target is missing required {0} column")]
    MissingColumn(String),
    #[error("hook target is missing required {0}")]
    MissingLiteral(String),
}

impl From<HookError> for crate::DbCacheError {
    fn from(error: HookError) -> Self {
        hydracache::CacheError::Backend(format!("hydracache hook error: {error}")).into()
    }
}

fn hook_schema_statements_sqlite(table: &str) -> Vec<String> {
    vec![
        "create table if not exists hydracache_hook_schema (
    artifact text primary key,
    version integer not null,
    table_name text not null,
    installed_at_ms integer not null
)"
        .to_owned(),
        format!(
            "insert or replace into hydracache_hook_schema (artifact, version, table_name, installed_at_ms)
values ('{HOOK_SCHEMA_ARTIFACT}', {HOOK_SCHEMA_VERSION}, '{}', cast(strftime('%s', 'now') as integer) * 1000)",
            sql_literal(table)
        ),
    ]
}

fn hook_schema_statements_postgres(table: &str) -> Vec<String> {
    vec![
        "create table if not exists hydracache_hook_schema (
    artifact text primary key,
    version bigint not null,
    table_name text not null,
    installed_at_ms bigint not null
);"
        .to_owned(),
        format!(
            "insert into hydracache_hook_schema (artifact, version, table_name, installed_at_ms)
values ('{HOOK_SCHEMA_ARTIFACT}', {HOOK_SCHEMA_VERSION}, '{}', (extract(epoch from clock_timestamp()) * 1000)::bigint)
on conflict (artifact) do update set version = excluded.version, table_name = excluded.table_name, installed_at_ms = excluded.installed_at_ms;",
            sql_literal(table)
        ),
    ]
}

fn hook_schema_statements_mysql(table: &str) -> Vec<String> {
    vec![
        "create table if not exists hydracache_hook_schema (
    artifact varchar(191) primary key,
    version bigint not null,
    table_name varchar(191) not null,
    installed_at_ms bigint not null
);"
        .to_owned(),
        format!(
            "insert into hydracache_hook_schema (artifact, version, table_name, installed_at_ms)
values ('{HOOK_SCHEMA_ARTIFACT}', {HOOK_SCHEMA_VERSION}, '{}', unix_timestamp(current_timestamp(3)) * 1000)
on duplicate key update version = values(version), table_name = values(table_name), installed_at_ms = values(installed_at_ms);",
            sql_literal(table)
        ),
    ]
}

fn render_sqlite_insert(
    namespace: &str,
    table: &str,
    operation: HookOperation,
    target: &HookInvalidationTarget,
) -> Result<String, HookError> {
    let row = operation.sqlite_row_ref();
    let target = SqlTargetExpr::sqlite(row, target)?;
    let commit = format!(
        "'hook:{table}:{}:' || {}",
        operation.as_str(),
        target.value_expr
    );
    let target_hash = target.hash_expr.clone();
    Ok(format!(
        "insert or ignore into hydracache_invalidation_outbox (
    id, namespace, commit_position, target_hash, intent_kind,
    cache_key, cache_tag, entity_name, collection_name, reason,
    created_at_ms, available_at_ms
) values (
    'hook:{namespace}:' || {commit} || ':' || {target_hash},
    '{namespace}',
    {commit},
    {target_hash},
    '{}',
    {},
    {},
    {},
    {},
    'hydracache hook {table} {}',
    cast(strftime('%s', 'now') as integer) * 1000,
    cast(strftime('%s', 'now') as integer) * 1000
);",
        target.intent_kind,
        target.cache_key_expr,
        target.cache_tag_expr,
        target.entity_name_expr,
        target.collection_name_expr,
        operation.as_str()
    ))
}

fn render_postgres_insert(
    namespace: &str,
    table: &str,
    operation: HookOperation,
    target: &HookInvalidationTarget,
) -> Result<String, HookError> {
    let row = operation.sqlite_row_ref();
    let target = SqlTargetExpr::postgres(row, target)?;
    let commit = format!(
        "'hook:{table}:{}:' || {}",
        operation.as_str(),
        target.value_expr
    );
    Ok(format!(
        "insert into hydracache_invalidation_outbox (
    id, namespace, commit_position, target_hash, intent_kind,
    cache_key, cache_tag, entity_name, collection_name, reason,
    created_at_ms, available_at_ms
) values (
    'hook:{namespace}:' || {commit} || ':' || {hash},
    '{namespace}',
    {commit},
    {hash},
    '{kind}',
    {cache_key},
    {cache_tag},
    {entity_name},
    {collection_name},
    'hydracache hook {table} {op}',
    (extract(epoch from clock_timestamp()) * 1000)::bigint,
    (extract(epoch from clock_timestamp()) * 1000)::bigint
) on conflict (namespace, commit_position, target_hash) do nothing;",
        hash = target.hash_expr,
        kind = target.intent_kind,
        cache_key = target.cache_key_expr,
        cache_tag = target.cache_tag_expr,
        entity_name = target.entity_name_expr,
        collection_name = target.collection_name_expr,
        op = operation.as_str(),
    ))
}

fn render_mysql_insert(
    namespace: &str,
    table: &str,
    operation: HookOperation,
    target: &HookInvalidationTarget,
) -> Result<String, HookError> {
    let row = operation.sqlite_row_ref();
    let target = SqlTargetExpr::mysql(row, target)?;
    let commit = format!(
        "concat('hook:{table}:{}:', {})",
        operation.as_str(),
        target.value_expr
    );
    Ok(format!(
        "insert ignore into hydracache_invalidation_outbox (
    id, namespace, commit_position, target_hash, intent_kind,
    cache_key, cache_tag, entity_name, collection_name, reason,
    created_at_ms, available_at_ms
) values (
    concat('hook:{namespace}:', {commit}, ':', {hash}),
    '{namespace}',
    {commit},
    {hash},
    '{kind}',
    {cache_key},
    {cache_tag},
    {entity_name},
    {collection_name},
    'hydracache hook {table} {op}',
    unix_timestamp(current_timestamp(3)) * 1000,
    unix_timestamp(current_timestamp(3)) * 1000
);",
        hash = target.hash_expr,
        kind = target.intent_kind,
        cache_key = target.cache_key_expr,
        cache_tag = target.cache_tag_expr,
        entity_name = target.entity_name_expr,
        collection_name = target.collection_name_expr,
        op = operation.as_str(),
    ))
}

struct SqlTargetExpr {
    intent_kind: &'static str,
    value_expr: String,
    hash_expr: String,
    cache_key_expr: String,
    cache_tag_expr: String,
    entity_name_expr: String,
    collection_name_expr: String,
}

impl SqlTargetExpr {
    fn sqlite(row: &str, target: &HookInvalidationTarget) -> Result<Self, HookError> {
        Self::new(row, target, SqlFlavor::Sqlite)
    }

    fn postgres(row: &str, target: &HookInvalidationTarget) -> Result<Self, HookError> {
        Self::new(row, target, SqlFlavor::Postgres)
    }

    fn mysql(row: &str, target: &HookInvalidationTarget) -> Result<Self, HookError> {
        Self::new(row, target, SqlFlavor::MySql)
    }

    fn new(
        row: &str,
        target: &HookInvalidationTarget,
        flavor: SqlFlavor,
    ) -> Result<Self, HookError> {
        target.validate()?;
        let null = "null".to_owned();
        match target {
            HookInvalidationTarget::KeyColumn { column } => {
                validate_identifier(column)?;
                let value = flavor.column_text(row, column);
                Ok(Self {
                    intent_kind: "key",
                    value_expr: value.clone(),
                    hash_expr: flavor.concat(&["'key:'", &value]),
                    cache_key_expr: value,
                    cache_tag_expr: null.clone(),
                    entity_name_expr: null.clone(),
                    collection_name_expr: null,
                })
            }
            HookInvalidationTarget::Tag { tag } => {
                let value = flavor.literal(tag);
                Ok(Self {
                    intent_kind: "tag",
                    value_expr: value.clone(),
                    hash_expr: flavor.concat(&["'tag:'", &value]),
                    cache_key_expr: null.clone(),
                    cache_tag_expr: value,
                    entity_name_expr: null.clone(),
                    collection_name_expr: null,
                })
            }
            HookInvalidationTarget::TagColumn { prefix, column } => {
                validate_identifier(column)?;
                let column = flavor.column_text(row, column);
                let value = flavor.concat(&[&flavor.literal(&format!("{prefix}:")), &column]);
                Ok(Self {
                    intent_kind: "tag",
                    value_expr: value.clone(),
                    hash_expr: flavor.concat(&["'tag:'", &value]),
                    cache_key_expr: null.clone(),
                    cache_tag_expr: value,
                    entity_name_expr: null.clone(),
                    collection_name_expr: null,
                })
            }
            HookInvalidationTarget::Entity { entity, key_column } => {
                validate_identifier(key_column)?;
                let key = flavor.column_text(row, key_column);
                let entity_literal = flavor.literal(entity);
                Ok(Self {
                    intent_kind: "entity",
                    value_expr: key.clone(),
                    hash_expr: flavor.concat(&["'entity:'", &entity_literal, "':'", &key]),
                    cache_key_expr: key,
                    cache_tag_expr: null.clone(),
                    entity_name_expr: entity_literal,
                    collection_name_expr: null,
                })
            }
            HookInvalidationTarget::Collection { collection } => {
                let value = flavor.literal(collection);
                Ok(Self {
                    intent_kind: "collection",
                    value_expr: value.clone(),
                    hash_expr: flavor.concat(&["'collection:'", &value]),
                    cache_key_expr: null.clone(),
                    cache_tag_expr: null.clone(),
                    entity_name_expr: null.clone(),
                    collection_name_expr: value,
                })
            }
        }
    }
}

#[derive(Debug, Clone, Copy)]
enum SqlFlavor {
    Sqlite,
    Postgres,
    MySql,
}

impl SqlFlavor {
    fn literal(self, value: &str) -> String {
        format!("'{}'", sql_literal(value))
    }

    fn column_text(self, row: &str, column: &str) -> String {
        match self {
            Self::Sqlite | Self::Postgres => format!("cast({row}.{column} as text)"),
            Self::MySql => format!("cast({row}.{column} as char)"),
        }
    }

    fn concat(self, parts: &[&str]) -> String {
        match self {
            Self::Sqlite | Self::Postgres => parts.join(" || "),
            Self::MySql => format!("concat({})", parts.join(", ")),
        }
    }
}

fn validate_identifier(identifier: &str) -> Result<(), HookError> {
    let valid = !identifier.is_empty()
        && identifier
            .chars()
            .all(|ch| ch.is_ascii_alphanumeric() || ch == '_')
        && identifier
            .chars()
            .next()
            .is_some_and(|ch| ch.is_ascii_alphabetic() || ch == '_');
    if valid {
        Ok(())
    } else {
        Err(HookError::InvalidIdentifier(identifier.to_owned()))
    }
}

fn sql_literal(value: &str) -> String {
    value.replace('\'', "''")
}

impl fmt::Display for HookDialect {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter.write_str(match self {
            Self::Postgres => "postgres",
            Self::MySql => "mysql",
            Self::Sqlite => "sqlite",
        })
    }
}

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

    #[test]
    fn schema_version_names_table_and_dialect() {
        let version = HookPlan::sqlite("users").schema_version();

        assert_eq!(version.artifact, HOOK_SCHEMA_ARTIFACT);
        assert_eq!(version.version, HOOK_SCHEMA_VERSION);
        assert_eq!(version.table, "users");
        assert_eq!(version.dialect, HookDialect::Sqlite);
    }
}