feat: uniq tenant_users

This commit is contained in:
Rogee
2024-12-02 11:29:15 +08:00
parent d1a2a80859
commit 2b4cfb1a1e
7 changed files with 198 additions and 37 deletions

View File

@@ -3,6 +3,7 @@ package db
import (
"context"
"database/sql"
"fmt"
"backend/common/consts"
@@ -15,3 +16,13 @@ func FromContext(ctx context.Context, db *sql.DB) qrm.DB {
}
return db
}
func TruncateAllTables(ctx context.Context, db *sql.DB, tableName ...string) error {
for _, name := range tableName {
sql := fmt.Sprintf("TRUNCATE TABLE %s CASCADE", name)
if _, err := db.ExecContext(ctx, sql); err != nil {
return err
}
}
return nil
}

View File

@@ -1,11 +1,33 @@
package pg
import (
"database/sql/driver"
"encoding/json"
"errors"
)
type UserOAuth struct {
AccessToken string `json:"access_token"`
ExpiresIn int64 `json:"expires_in"`
IsSnapshotuser int64 `json:"is_snapshotuser"`
Openid string `json:"openid"`
RefreshToken string `json:"refresh_token"`
Scope string `json:"scope"`
Unionid string `json:"unionid"`
AccessToken string `json:"access_token,omitempty"`
ExpiresIn int64 `json:"expires_in,omitempty"`
IsSnapshotuser int64 `json:"is_snapshotuser,omitempty"`
Openid string `json:"openid,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Scope string `json:"scope,omitempty"`
Unionid string `json:"unionid,omitempty"`
}
func (x UserOAuth) Scan(value interface{}) (err error) {
switch v := value.(type) {
case string:
return json.Unmarshal([]byte(v), &x)
case []byte:
return json.Unmarshal(v, &x)
case *string:
return json.Unmarshal([]byte(*v), &x)
}
return errors.New("Unknown type for ")
}
func (x UserOAuth) Value() (driver.Value, error) {
return json.Marshal(x)
}