REORDER ME into database
This commit is contained in:
		@@ -63,7 +63,7 @@ func (db *DB) Close() error {
 | 
			
		||||
 | 
			
		||||
// Initialize the database schema
 | 
			
		||||
func (db *DB) Initialize(schemaPath string) error {
 | 
			
		||||
	err := db.checkIsInitialized()
 | 
			
		||||
	err := db.CheckInitialized()
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
@@ -82,7 +82,8 @@ func (db *DB) Initialize(schemaPath string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (db *DB) checkIsInitialized() error {
 | 
			
		||||
// CheckInitialized returns nil if the database is initialized and an error otherwise
 | 
			
		||||
func (db *DB) CheckInitialized() error {
 | 
			
		||||
	var count int
 | 
			
		||||
	err := db.conn.QueryRow("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='settings'").Scan(&count)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -95,7 +96,8 @@ func (db *DB) checkIsInitialized() error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (db *DB) getSchemaVersion() (int, error) {
 | 
			
		||||
// GetSchemaVersion returns the schema version or an error
 | 
			
		||||
func (db *DB) GetSchemaVersion() (int, error) {
 | 
			
		||||
	var version string
 | 
			
		||||
	err := db.conn.QueryRow("SELECT value FROM settings WHERE key='schema-version'").Scan(&version)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -116,11 +118,11 @@ func (db *DB) getSchemaVersion() (int, error) {
 | 
			
		||||
 | 
			
		||||
// CheckSchemaVersion verifies that the schema is initialized and has the correct version
 | 
			
		||||
func (db *DB) CheckSchemaVersion() error {
 | 
			
		||||
	err := db.checkIsInitialized()
 | 
			
		||||
	err := db.CheckInitialized()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	version_, err := db.getSchemaVersion()
 | 
			
		||||
	version_, err := db.GetSchemaVersion()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@@ -132,9 +134,7 @@ func (db *DB) CheckSchemaVersion() error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Transaction executes a function within a database transaction,
 | 
			
		||||
// handling commit/rollback automatically.
 | 
			
		||||
func (db *DB) Transaction(ctx context.Context, fn func(*sql.Tx) error) error {
 | 
			
		||||
func (db *DB) transaction(ctx context.Context, fn func(*sql.Tx) error) error {
 | 
			
		||||
	tx, err := db.conn.BeginTx(ctx, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("failed to begin transaction: %w", err)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user