go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/db/interfaces.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package db 9 10 // TableNameProvider is a type that implements the TableName() function. 11 // The only required method is TableName() string that returns the name of the table in the database this type is mapped to. 12 // 13 // type MyDatabaseMappedObject { 14 // Mycolumn `db:"my_column"` 15 // } 16 // func (_ MyDatabaseMappedObject) TableName() string { 17 // return "my_database_mapped_object" 18 // } 19 // 20 // If you require different table names based on alias, create another type. 21 type TableNameProvider interface { 22 TableName() string 23 } 24 25 // ColumnMetaCacheKeyProvider is a provider for a column meta key. 26 type ColumnMetaCacheKeyProvider interface { 27 ColumnMetaCacheKey() string 28 } 29 30 // Populatable is an interface that you can implement if your object is read often and is performance critical. 31 type Populatable interface { 32 Populate(rows Rows) error 33 } 34 35 // RowsConsumer is the function signature that is called from within Each(). 36 type RowsConsumer func(r Rows) error 37 38 // Scanner is a type that can scan into variadic values. 39 type Scanner interface { 40 Scan(...interface{}) error 41 } 42 43 // ColumnsProvider is a type that can return columns. 44 type ColumnsProvider interface { 45 Columns() ([]string, error) 46 } 47 48 // Rows provides the relevant fields to populate by name. 49 type Rows interface { 50 Scanner 51 ColumnsProvider 52 }