github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/datastore/revisionparsing/revisionparsing.go (about) 1 package revisionparsing 2 3 import ( 4 "github.com/authzed/spicedb/internal/datastore/crdb" 5 "github.com/authzed/spicedb/internal/datastore/memdb" 6 "github.com/authzed/spicedb/internal/datastore/mysql" 7 "github.com/authzed/spicedb/internal/datastore/postgres" 8 "github.com/authzed/spicedb/internal/datastore/revisions" 9 "github.com/authzed/spicedb/internal/datastore/spanner" 10 "github.com/authzed/spicedb/pkg/datastore" 11 ) 12 13 // ParsingFunc is a function that can parse a string into a revision. 14 type ParsingFunc func(revisionStr string) (rev datastore.Revision, err error) 15 16 // ParseRevisionStringByDatastoreEngineID defines a map from datastore engine ID to its associated 17 // revision parsing function. 18 var ParseRevisionStringByDatastoreEngineID = map[string]ParsingFunc{ 19 memdb.Engine: ParsingFunc(memdb.ParseRevisionString), 20 crdb.Engine: ParsingFunc(crdb.ParseRevisionString), 21 postgres.Engine: ParsingFunc(postgres.ParseRevisionString), 22 mysql.Engine: ParsingFunc(mysql.ParseRevisionString), 23 spanner.Engine: ParsingFunc(spanner.ParseRevisionString), 24 } 25 26 // MustParseRevisionForTest is a convenience ParsingFunc that can be used in tests and panics when parsing an error. 27 func MustParseRevisionForTest(revisionStr string) (rev datastore.Revision) { 28 rev, err := testParser(revisionStr) 29 if err != nil { 30 panic(err) 31 } 32 33 return rev 34 } 35 36 var testParser = revisions.RevisionParser(revisions.HybridLogicalClock)