11 Commits

Author SHA1 Message Date
b4529e018f Restructure dialects and add PostgreSQL support
Architecture Changes:
- Split dialect implementations into separate files for better organization
- Move SQLite dialect from dialect.go to sqlite.go
- Keep only Dialect interface in dialect.go with comprehensive documentation
- Each dialect now in its own file following single responsibility principle

New Features:
- Add PostgreSQL dialect support (Postgres() function)
- PostgreSQL uses SERIAL PRIMARY KEY (auto-incrementing integer)
- PostgreSQL uses $1, $2 placeholders instead of ? for parameters
- PostgreSQL uses SELECT 1 for table existence check (more efficient)
- Both dialects implement proper SQL identifier quoting for security

Testing:
- Add comprehensive dialect-specific tests in sqlite_test.go
- Add comprehensive dialect-specific tests in postgres_test.go
- Test SQL generation for all dialect methods
- Test SQL injection protection via identifier escaping
- All tests pass (8 test functions, 10 subtests)

Documentation:
- Update README with PostgreSQL usage example
- Add "Supported Databases" section listing SQLite and PostgreSQL
- Improve code examples with proper imports and error handling
- Document how to implement Dialect interface for other databases

File Structure:
- dialect.go: Interface definition only (18 lines)
- sqlite.go: SQLite dialect implementation (39 lines)
- postgres.go: PostgreSQL dialect implementation (42 lines)
- sqlite_test.go: SQLite dialect tests (67 lines)
- postgres_test.go: PostgreSQL dialect tests (67 lines)

Security:
- Both dialects use quoteIdentifier() for SQL injection protection
- Identifiers are quoted and internal quotes are escaped
- Follows SQL standard quoting mechanism (double quotes for escaping)

This change maintains backward compatibility while adding PostgreSQL support
and improving code organization for future dialect additions.
2026-01-18 01:34:09 -08:00
9b998b7904 Refactor and improve code quality, fix security issues and documentation
Security Fixes:
- Add SQL injection protection in dialect.go using proper identifier quoting
- Implement quoteIdentifier() method to escape SQL identifiers safely
- Fix resource leak in dbVersion() by adding deferred rows.Close()
- Fix incorrect error handling in dbVersion() to properly propagate errors

Code Quality Improvements:
- Replace custom Error struct with idiomatic fmt.Errorf with %w verb
- Simplify error handling by replacing nested if-err-nil with early returns
- Remove named return values with implicit returns for clarity
- Update interface{} to any (Go 1.18+ style)
- Fix variable shadowing in Apply loop (use m.Description instead of migrations[i])

Test Improvements:
- Fix variable shadowing bug in createTestDB() that caused nil pointer panics
- Update SQL driver from github.com/mattn/go-sqlite3 to modernc.org/sqlite
- Fix driver name from "sqlite3" to "sqlite" for modernc.org/sqlite
- Add missing error check for r.Scan() in TestApply
- Make test error handling consistent by using t.Fatal() throughout
- Simplify test helper functions with early returns

Documentation Fixes:
- Fix README example to use 'Apply' field instead of incorrect 'F' field
- Update README example to match actual test code (sex instead of gender)
- Fix typos: "datbase" → "database", "datbases" → "databases"
- Improve README clarity with proper punctuation and formatting
- Update doc.go with correct spelling

Dependencies:
- Update go.mod to Go 1.25
- Switch to modernc.org/sqlite v1.44.0 (pure Go SQLite driver)
- Add all required indirect dependencies

All changes maintain backward compatibility and pass existing tests.
2026-01-18 01:34:09 -08:00
ca2081c72c updates 2026-01-18 01:12:36 -08:00
Colin Henry
46e6c1272d Update README.md 2022-04-13 08:16:46 -07:00
Colin Henry
87ae7265f4 Update README.md
fixed typo
2021-09-12 15:51:43 -07:00
Colin Henry
60875e60d5 added license v0.0.4 2021-07-10 16:21:56 -07:00
Colin Henry
29d3e5df23 retract previous versions v0.0.3 2021-07-10 16:18:59 -07:00
Colin Henry
4ae15885b6 fixed module path v0.0.1 v0.0.2 2021-07-10 14:43:28 -07:00
Colin Henry
b0ef8ca156 added readme 0.0.0 0.0.1 2021-07-10 14:36:26 -07:00
Colin Henry
a3d0263698 introduced the concept of a dialect, to provide the exact SQL needed. 2021-07-10 13:09:26 -07:00
Colin Henry
f7c677a3f5 temporary holding ground for migrate 2021-06-04 17:57:45 -07:00