Documentation
¶
Index ¶
- Variables
- type ColumnOrderBy
- type GoogleSheetDeleteStmt
- type GoogleSheetInsertStmt
- type GoogleSheetKVStore
- type GoogleSheetKVStoreConfig
- type GoogleSheetKVStoreV2
- type GoogleSheetKVStoreV2Config
- type GoogleSheetRowStore
- type GoogleSheetRowStoreConfig
- type GoogleSheetSelectStmt
- type GoogleSheetUpdateStmt
- type KVMode
- type OrderBy
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( NewGoogleSheetKVStore = store.NewGoogleSheetKVStore NewGoogleSheetKVStoreV2 = store.NewGoogleSheetKVStoreV2 KVModeDefault = models.KVModeDefault KVModeAppendOnly = models.KVModeAppendOnly )
View Source
var ( NewGoogleSheetRowStore = store.NewGoogleSheetRowStore OrderByAsc = models.OrderByAsc OrderByDesc = models.OrderByDesc )
View Source
var (
GoogleAuthScopes = auth.GoogleSheetsReadWrite
)
GoogleAuthScopes specifies the list of Google Auth scopes required to run FreeDB implementations properly.
Functions ¶
This section is empty.
Types ¶
type ColumnOrderBy ¶
type ColumnOrderBy = models.ColumnOrderBy
type GoogleSheetDeleteStmt ¶
type GoogleSheetDeleteStmt = store.GoogleSheetDeleteStmt
type GoogleSheetInsertStmt ¶
type GoogleSheetInsertStmt = store.GoogleSheetInsertStmt
type GoogleSheetKVStore ¶
type GoogleSheetKVStore = store.GoogleSheetKVStore
Example ¶
googleAuth, err := auth.NewServiceFromFile(
"<path_to_file>",
GoogleAuthScopes,
auth.ServiceConfig{},
)
if err != nil {
panic(err)
}
store := NewGoogleSheetKVStore(
googleAuth,
"spreadsheet_id",
"sheet_name",
GoogleSheetKVStoreConfig{
Mode: KVModeDefault,
},
)
val, err := store.Get(context.Background(), "key1")
if err != nil {
panic(err)
}
fmt.Println("get key", val)
err = store.Set(context.Background(), "key1", []byte("value1"))
if err != nil {
panic(err)
}
err = store.Delete(context.Background(), "key1")
if err != nil {
panic(err)
}
type GoogleSheetKVStoreConfig ¶
type GoogleSheetKVStoreConfig = store.GoogleSheetKVStoreConfig
type GoogleSheetKVStoreV2 ¶ added in v1.0.2
type GoogleSheetKVStoreV2 = store.GoogleSheetKVStoreV2
Example ¶
googleAuth, err := auth.NewServiceFromFile(
"<path_to_file>",
GoogleAuthScopes,
auth.ServiceConfig{},
)
if err != nil {
panic(err)
}
storeV2 := NewGoogleSheetKVStoreV2(
googleAuth,
"spreadsheet_id",
"sheet_name",
GoogleSheetKVStoreV2Config{
Mode: KVModeDefault,
},
)
val, err := storeV2.Get(context.Background(), "key1")
if err != nil {
panic(err)
}
fmt.Println("get key", val)
err = storeV2.Set(context.Background(), "key1", []byte("value1"))
if err != nil {
panic(err)
}
err = storeV2.Delete(context.Background(), "key1")
if err != nil {
panic(err)
}
type GoogleSheetKVStoreV2Config ¶ added in v1.0.2
type GoogleSheetKVStoreV2Config = store.GoogleSheetKVStoreV2Config
type GoogleSheetRowStore ¶
type GoogleSheetRowStore = store.GoogleSheetRowStore
Example ¶
// Initialize authentication
googleAuth, err := auth.NewServiceFromFile(
"<path_to_service_account_file>",
GoogleAuthScopes,
auth.ServiceConfig{},
)
if err != nil {
panic(err)
}
// Create row store with columns definition
store := NewGoogleSheetRowStore(
googleAuth,
"<spreadsheet_id>",
"<sheet_name>",
GoogleSheetRowStoreConfig{
Columns: []string{"name", "age", "email"},
},
)
// Insert some rows
type Person struct {
Name string `db:"name"`
Age int `db:"age"`
Email string `db:"email"`
}
err = store.Insert(
Person{Name: "Alice", Age: 30, Email: "alice@example.com"},
Person{Name: "Bob", Age: 25, Email: "bob@example.com"},
).Exec(context.Background())
if err != nil {
panic(err)
}
// Query rows
var people []Person
err = store.Select(&people).
Where("age > ?", 20).
OrderBy([]ColumnOrderBy{{Column: "age", OrderBy: OrderByAsc}}).
Limit(10).
Exec(context.Background())
if err != nil {
panic(err)
}
fmt.Println("Selected people:", people)
// Update rows
update := map[string]interface{}{"age": 31}
err = store.Update(update).Where("name = ?", "Alice").
Exec(context.Background())
if err != nil {
panic(err)
}
// Count rows
count, err := store.Count().
Where("age > ?", 20).
Exec(context.Background())
if err != nil {
panic(err)
}
fmt.Println("Number of people over 20:", count)
// Delete rows
err = store.Delete().
Where("name = ?", "Bob").
Exec(context.Background())
if err != nil {
panic(err)
}
// Clean up
err = store.Close(context.Background())
if err != nil {
panic(err)
}
type GoogleSheetRowStoreConfig ¶
type GoogleSheetRowStoreConfig = store.GoogleSheetRowStoreConfig
type GoogleSheetSelectStmt ¶
type GoogleSheetSelectStmt = store.GoogleSheetSelectStmt
type GoogleSheetUpdateStmt ¶
type GoogleSheetUpdateStmt = store.GoogleSheetUpdateStmt
Directories
¶
| Path | Synopsis |
|---|---|
|
google
|
|
|
auth
Package auth provides general Google authentication implementation agnostic to what specific Google services or resources are used.
|
Package auth provides general Google authentication implementation agnostic to what specific Google services or resources are used. |
|
internal
|
|
Click to show internal directories.
Click to hide internal directories.