Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change freeleh to freedb and add _rid is not null into where clauses #6

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GoFreeLeh
# GoFreeDB

![Unit Test](https://github.com/FreeLeh/GoFreeLeh/actions/workflows/unit_test.yml/badge.svg)
![Unit Test](https://github.com/FreeLeh/GoFreeDB/actions/workflows/unit_test.yml/badge.svg)

<div>
<h2 align="center">
Expand All @@ -11,13 +11,13 @@
</h2>
</div>

`GoFreeLeh` is a Golang library providing common and familiar interfaces on top of common free services we have access to.
`GoFreeDB` is a Golang library providing common and familiar interfaces on top of common free services we have access to.

## Why do you need this library?

Our main goal is to make developers who want to **just start their small personal projects so much easier without thinking too much about the setup required to get started**. We can leverage a bunch of well known free services available to us like Google Sheets and Telegram. We want to use these services as our **easy-to-setup and "managed" database or even a message queue**.

`GoFreeLeh` is just the beginning. It is very likely we will explore other languages (e.g. Java, Kotlin, Swift, etc.) to support in the future.
`GoFreeDB` is just the beginning. It is very likely we will explore other languages (e.g. Java, Kotlin, Swift, etc.) to support in the future.

> Check out [PyFreeLeh](https://github.com/FreeLeh/PyFreeLeh) for the Python version!
Expand All @@ -34,7 +34,7 @@ There are other ideas we have in our backlog:
2. A simple message queue on top of Telegram Channels.

We are quite open to knowing any other free services we can leverage on.<br>
Please suggest your ideas in the [issues](https://github.com/FreeLeh/GoFreeLeh/issues) page!
Please suggest your ideas in the [issues](https://github.com/FreeLeh/GoFreeDB/issues) page!

## What can I do with these interfaces/abstractions?

Expand Down Expand Up @@ -76,7 +76,7 @@ Here are a few ideas we thought of:
# Installation

```
go get github.com/FreeLeh/GoFreeLeh
go get github.com/FreeLeh/GoFreeDB
```

# Key Value Store
Expand All @@ -100,11 +100,11 @@ auth, err := auth.NewOAuth2FromFile(
)

// Below are the same regardless of the auth client chosen above.
kv := freeleh.NewGoogleSheetKVStore(
kv := freedb.NewGoogleSheetKVStore(
auth,
"<spreadsheet_id>",
"<sheet_name>",
freeleh.GoogleSheetKVStoreConfig{Mode: freeleh.KVSetModeAppendOnly},
freedb.GoogleSheetKVStoreConfig{Mode: freedb.KVSetModeAppendOnly},
)
defer kv.Close(context.Background())

Expand Down Expand Up @@ -155,10 +155,10 @@ There are 2 different modes supported:

```go
// Default mode
kv := freeleh.NewGoogleSheetKVStore(auth, "<spreadsheet_id>", "<sheet_name>", freeleh.GoogleSheetKVStoreConfig{Mode: freeleh.KVModeDefault})
kv := freedb.NewGoogleSheetKVStore(auth, "<spreadsheet_id>", "<sheet_name>", freedb.GoogleSheetKVStoreConfig{Mode: freedb.KVModeDefault})

// Append only mode
kv := freeleh.NewGoogleSheetKVStore(auth, "<spreadsheet_id>", "<sheet_name>", freeleh.GoogleSheetKVStoreConfig{Mode: freeleh.KVModeAppendOnly})
kv := freedb.NewGoogleSheetKVStore(auth, "<spreadsheet_id>", "<sheet_name>", freedb.GoogleSheetKVStoreConfig{Mode: freedb.KVModeAppendOnly})
```

#### Default Mode
Expand Down Expand Up @@ -250,11 +250,11 @@ auth, err := auth.NewOAuth2FromFile(
)

// Below are the same regardless of the auth client chosen above.
store := freeleh.NewGoogleSheetsRowStore(
store := freedb.NewGoogleSheetsRowStore(
auth,
"<spreadsheet_id>",
"<sheet_name>",
freeleh.GoogleSheetRowStoreConfig{Columns: []string{"name", "age"}},
freedb.GoogleSheetRowStoreConfig{Columns: []string{"name", "age"}},
)
defer store.Close(context.Background())

Expand Down Expand Up @@ -552,7 +552,7 @@ auth, err := auth.NewServiceFromFile(
1. If you want to manually edit the Google Sheet, you can do it, but you need to understand the value encoding scheme.
2. It is not easy to support concurrent operations. Only few modes or abstractions allow concurrent operations.
3. Performance is not a high priority for this project.
4. `GoFreeLeh` does not support OAuth2 flow that spans across frontend and backend yet.
4. `GoFreeDB` does not support OAuth2 flow that spans across frontend and backend yet.

### (Google Sheets Key Value) Exclamation Mark `!` Prefix

Expand Down Expand Up @@ -583,4 +583,4 @@ auth, err := auth.NewServiceFromFile(

# License

This project is [MIT licensed](https://github.com/FreeLeh/GoFreeLeh/blob/main/LICENSE).
This project is [MIT licensed](https://github.com/FreeLeh/GoFreeDB/blob/main/LICENSE).
2 changes: 1 addition & 1 deletion codec.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package freeleh
package freedb

import "errors"

Expand Down
2 changes: 1 addition & 1 deletion codec_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package freeleh
package freedb

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/FreeLeh/GoFreeLeh
module github.com/FreeLeh/GoFreeDB

go 1.18

Expand Down
2 changes: 1 addition & 1 deletion google/auth/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

"github.com/FreeLeh/GoFreeLeh/internal/google/fixtures"
"github.com/FreeLeh/GoFreeDB/internal/google/fixtures"
"github.com/stretchr/testify/assert"
"golang.org/x/oauth2"
)
Expand Down
2 changes: 1 addition & 1 deletion google/auth/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package auth
import (
"testing"

"github.com/FreeLeh/GoFreeLeh/internal/google/fixtures"
"github.com/FreeLeh/GoFreeDB/internal/google/fixtures"
"github.com/stretchr/testify/assert"
"golang.org/x/oauth2"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/google/sheets/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (w *Wrapper) execQueryRows(
) (rawQueryRowsResult, error) {
params := url.Values{}
params.Add("sheet", sheetName)
params.Add("tqx", "responseHandler:freeleh")
params.Add("tqx", "responseHandler:freedb")
params.Add("tq", query)

header := 0
Expand Down
8 changes: 4 additions & 4 deletions internal/google/sheets/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"
"testing"

"github.com/FreeLeh/GoFreeLeh/google/auth"
"github.com/FreeLeh/GoFreeLeh/internal/google/fixtures"
"github.com/FreeLeh/GoFreeDB/google/auth"
"github.com/FreeLeh/GoFreeDB/internal/google/fixtures"
"github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
)
Expand Down Expand Up @@ -589,13 +589,13 @@ func TestQueryRows(t *testing.T) {
t.Run("successful", func(t *testing.T) {
expectedParams := map[string]string{
"sheet": "s1",
"tqx": "responseHandler:freeleh",
"tqx": "responseHandler:freedb",
"tq": "select A, B",
"headers": "1",
}
resp := `
/*O_o*/
freeleh({"version":"0.6","reqId":"0","status":"ok","sig":"141753603","table":{"cols":[{"id":"A","label":"","type":"string"},{"id":"B","label":"","type":"number","pattern":"General"}],"rows":[{"c":[{"v":"k1"},{"v":103.51,"f":"103.51"}]},{"c":[{"v":"k2"},{"v":111.0,"f":"111"}]},{"c":[{"v":"k3"},{"v":123.0,"f":"123"}]}],"parsedNumHeaders":0}})
freedb({"version":"0.6","reqId":"0","status":"ok","sig":"141753603","table":{"cols":[{"id":"A","label":"","type":"string"},{"id":"B","label":"","type":"number","pattern":"General"}],"rows":[{"c":[{"v":"k1"},{"v":103.51,"f":"103.51"}]},{"c":[{"v":"k2"},{"v":111.0,"f":"111"}]},{"c":[{"v":"k3"},{"v":123.0,"f":"123"}]}],"parsedNumHeaders":0}})
`

gock.New("https://docs.google.com").
Expand Down
4 changes: 2 additions & 2 deletions kv.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package freeleh
package freedb

import (
"context"
"errors"
"fmt"

"github.com/FreeLeh/GoFreeLeh/internal/google/sheets"
"github.com/FreeLeh/GoFreeDB/internal/google/sheets"
)

// GoogleSheetKVStoreConfig defines a list of configurations that can be used to customise how the GoogleSheetKVStore works.
Expand Down
4 changes: 2 additions & 2 deletions kv_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package freeleh
package freedb

import (
"context"
"fmt"
"testing"

"github.com/FreeLeh/GoFreeLeh/google/auth"
"github.com/FreeLeh/GoFreeDB/google/auth"
"github.com/stretchr/testify/assert"
)

Expand Down
26 changes: 8 additions & 18 deletions models.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package freeleh
package freedb

import (
"context"
"errors"
"github.com/FreeLeh/GoFreeLeh/google/auth"
"regexp"
"strconv"

"github.com/FreeLeh/GoFreeLeh/internal/google/sheets"
"github.com/FreeLeh/GoFreeDB/google/auth"

"github.com/FreeLeh/GoFreeDB/internal/google/sheets"
)

// KVMode defines the mode of the key value store.
Expand Down Expand Up @@ -36,11 +36,6 @@ const (
kvGetDefaultQueryTemplate = "=VLOOKUP(\"%s\", %s, 2, FALSE)"
kvFindKeyA1RangeQueryTemplate = "=MATCH(\"%s\", %s, 0)"

rowGetIndicesQueryTemplate = "=JOIN(\",\", ARRAYFORMULA(QUERY({%s, ROW(%s)}, \"%s\")))"
rwoCountQueryTemplate = "=COUNT(QUERY(%s, \"%s\"))"
rowUpdateModifyWhereNonEmptyTemplate = "%s IS NOT NULL AND %s"
rowUpdateModifyWhereEmptyTemplate = "%s IS NOT NULL"

naValue = "#N/A"
errorValue = "#ERROR!"
rowIdxCol = "_rid"
Expand All @@ -62,7 +57,10 @@ var (
defaultRowFullTableRange = "A2:" + generateColumnName(maxColumn-1)
rowDeleteRangeTemplate = "A%d:" + generateColumnName(maxColumn-1) + "%d"

lastColIdxName = "Col" + strconv.FormatInt(int64(maxColumn+1), 10)
// The first condition `_rid IS NOT NULL` is necessary to ensure we are just updating rows that are non-empty.
// This is required for UPDATE without WHERE clause (otherwise it will see every row as update target).
rowWhereNonEmptyConditionTemplate = rowIdxCol + " is not null AND %s"
rowWhereEmptyConditionTemplate = rowIdxCol + " is not null"

googleSheetSelectStmtStringKeyword = regexp.MustCompile("^(date|datetime|timeofday)")
)
Expand Down Expand Up @@ -102,14 +100,6 @@ func (m colsMapping) NameMap() map[string]string {
return result
}

func (m colsMapping) ColIdxNameMap() map[string]string {
result := make(map[string]string, 0)
for col, val := range m {
result[col] = "Col" + strconv.FormatInt(int64(val.idx+1), 10)
}
return result
}

// OrderBy defines the type of column ordering used for GoogleSheetRowStore.Select().
type OrderBy string

Expand Down
2 changes: 1 addition & 1 deletion models_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package freeleh
package freedb

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions row.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package freeleh
package freedb

import (
"context"
"errors"
"fmt"
"time"

"github.com/FreeLeh/GoFreeLeh/internal/google/sheets"
"github.com/FreeLeh/GoFreeDB/internal/google/sheets"
)

// GoogleSheetRowStoreConfig defines a list of configurations that can be used to customise how the GoogleSheetRowStore works.
Expand Down
4 changes: 2 additions & 2 deletions row_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package freeleh
package freedb

import (
"context"
"fmt"
"testing"

"github.com/FreeLeh/GoFreeLeh/google/auth"
"github.com/FreeLeh/GoFreeDB/google/auth"
"github.com/stretchr/testify/assert"
)

Expand Down
Loading