github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/internal/database/sqlcommon/provider.go (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package sqlcommon 18 19 import ( 20 "database/sql" 21 22 sq "github.com/Masterminds/squirrel" 23 migratedb "github.com/golang-migrate/migrate/v4/database" 24 ) 25 26 // Provider defines the interface an individual provider muse implement to customize the SQLCommon implementation 27 type Provider interface { 28 29 // Name is the name of the database driver 30 Name() string 31 32 // Open creates the DB instances 33 Open(url string) (*sql.DB, error) 34 35 // GetDriver returns the driver implementation 36 GetMigrationDriver(*sql.DB) (migratedb.Driver, error) 37 38 // PlaceholderFormat gets the Squirrel placeholder format 39 PlaceholderFormat() sq.PlaceholderFormat 40 41 // UpdateInsertForReturn updates the insert query for returning the Sequenc, and returns whether it needs to be run as a query to return the Sequence field 42 UpdateInsertForSequenceReturn(insert sq.InsertBuilder) (updatedInsert sq.InsertBuilder, runAsQuery bool) 43 44 // SequenceField must be auto added by the database to each table, via appropriate DDL in the migrations 45 // Different formats exist for putting a table prefix. QL is "id(prefix)" rather than "prefix.seq" 46 SequenceField(tableName string) string 47 }