| 547 | } |
| 548 | |
| 549 | func normalizeDatabaseURL(raw string) (string, error) { |
| 550 | value := strings.TrimSpace(raw) |
| 551 | if value == "" { |
| 552 | return "", errors.New("database url is empty") |
| 553 | } |
| 554 | |
| 555 | switch { |
| 556 | case strings.HasPrefix(value, "sqlite+aiosqlite:///"): |
| 557 | value = strings.TrimPrefix(value, "sqlite+aiosqlite:///") |
| 558 | case strings.HasPrefix(value, "sqlite:///"): |
| 559 | value = strings.TrimPrefix(value, "sqlite:///") |
| 560 | case strings.HasPrefix(value, "file:"): |
| 561 | value = strings.TrimPrefix(value, "file:") |
| 562 | } |
| 563 | |
| 564 | if value == ":memory:" { |
| 565 | return "file::memory:?cache=shared", nil |
| 566 | } |
| 567 | |
| 568 | path := filepath.FromSlash(value) |
| 569 | if !filepath.IsAbs(path) { |
| 570 | abs, err := filepath.Abs(path) |
| 571 | if err != nil { |
| 572 | return "", fmt.Errorf("resolve database path: %w", err) |
| 573 | } |
| 574 | path = abs |
| 575 | } |
| 576 | |
| 577 | return "file:" + filepath.ToSlash(path), nil |
| 578 | } |