-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: different db context, partition for cache (#13)
- Loading branch information
Showing
14 changed files
with
135 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,41 @@ | ||
package database | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
) | ||
|
||
type wrappedContext struct { | ||
context.Context | ||
wrapped interface{} | ||
ctx context.Context | ||
schemaGetter func() string | ||
} | ||
|
||
var _ DBContext = (*wrappedContext)(nil) | ||
|
||
func (w *wrappedContext) Schema() string { | ||
return w.schemaGetter() | ||
} | ||
|
||
func WrapContext(ctx context.Context) DBContext { | ||
return WrapContextWithSchema(ctx, "public") | ||
func (w *wrappedContext) Context() context.Context { | ||
return w.ctx | ||
} | ||
|
||
func (w *wrappedContext) Unwrap() interface{} { | ||
return w.wrapped | ||
} | ||
|
||
func WrapContext(ctx context.Context, data interface{}) DBContext { | ||
return WrapContextWithSchema(ctx, "public", data) | ||
} | ||
|
||
func WrapContextWithSchema(ctx context.Context, schema string) DBContext { | ||
return WrapContextWithSchemaGetter(ctx, func() string { return schema }) | ||
func WrapContextWithSchema(ctx context.Context, schema string, data interface{}) DBContext { | ||
return WrapContextWithSchemaGetter(ctx, func() string { return schema }, data) | ||
} | ||
|
||
func WrapContextWithSchemaGetter(ctx context.Context, schemaGetter func() string) DBContext { | ||
func WrapContextWithSchemaGetter(ctx context.Context, schemaGetter func() string, data interface{}) DBContext { | ||
return &wrappedContext{ | ||
Context: ctx, | ||
ctx: ctx, | ||
schemaGetter: schemaGetter, | ||
wrapped: data, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.