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