gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

basic.go (4135B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package db
     19 
     20 import "context"
     21 
     22 // Basic wraps basic database functionality.
     23 type Basic interface {
     24 	// CreateTable creates a table for the given interface.
     25 	// For implementations that don't use tables, this can just return nil.
     26 	CreateTable(ctx context.Context, i interface{}) Error
     27 
     28 	// CreateAllTables creates *all* tables necessary for the running of GoToSocial.
     29 	// Because it uses the 'if not exists' parameter it is safe to run against a GtS that's already been initialized.
     30 	CreateAllTables(ctx context.Context) Error
     31 
     32 	// DropTable drops the table for the given interface.
     33 	// For implementations that don't use tables, this can just return nil.
     34 	DropTable(ctx context.Context, i interface{}) Error
     35 
     36 	// Stop should stop and close the database connection cleanly, returning an error if this is not possible.
     37 	// If the database implementation doesn't need to be stopped, this can just return nil.
     38 	Stop(ctx context.Context) Error
     39 
     40 	// IsHealthy should return nil if the database connection is healthy, or an error if not.
     41 	IsHealthy(ctx context.Context) Error
     42 
     43 	// GetByID gets one entry by its id. In a database like postgres, this might be the 'id' field of the entry,
     44 	// for other implementations (for example, in-memory) it might just be the key of a map.
     45 	// The given interface i will be set to the result of the query, whatever it is. Use a pointer or a slice.
     46 	// In case of no entries, a 'no entries' error will be returned
     47 	GetByID(ctx context.Context, id string, i interface{}) Error
     48 
     49 	// GetWhere gets one entry where key = value. This is similar to GetByID but allows the caller to specify the
     50 	// name of the key to select from.
     51 	// The given interface i will be set to the result of the query, whatever it is. Use a pointer or a slice.
     52 	// In case of no entries, a 'no entries' error will be returned
     53 	GetWhere(ctx context.Context, where []Where, i interface{}) Error
     54 
     55 	// GetAll will try to get all entries of type i.
     56 	// The given interface i will be set to the result of the query, whatever it is. Use a pointer or a slice.
     57 	// In case of no entries, a 'no entries' error will be returned
     58 	GetAll(ctx context.Context, i interface{}) Error
     59 
     60 	// Put simply stores i. It is up to the implementation to figure out how to store it, and using what key.
     61 	// The given interface i will be set to the result of the query, whatever it is. Use a pointer or a slice.
     62 	Put(ctx context.Context, i interface{}) Error
     63 
     64 	// UpdateByID updates values of i based on its id.
     65 	// If any columns are specified, these will be updated exclusively.
     66 	// Otherwise, the whole model will be updated.
     67 	// The given interface i will be set to the result of the query, whatever it is. Use a pointer or a slice.
     68 	UpdateByID(ctx context.Context, i interface{}, id string, columns ...string) Error
     69 
     70 	// UpdateWhere updates column key of interface i with the given value, where the given parameters apply.
     71 	UpdateWhere(ctx context.Context, where []Where, key string, value interface{}, i interface{}) Error
     72 
     73 	// DeleteByID removes i with id id.
     74 	// If i didn't exist anyway, then no error should be returned.
     75 	DeleteByID(ctx context.Context, id string, i interface{}) Error
     76 
     77 	// DeleteWhere deletes i where key = value
     78 	// If i didn't exist anyway, then no error should be returned.
     79 	DeleteWhere(ctx context.Context, where []Where, i interface{}) Error
     80 }