Port all of the arcgis schema to using jet
Have not tested anything at this point, it just compiles.
This commit is contained in:
parent
89ed2003fa
commit
bab3200b6c
52 changed files with 479 additions and 13585 deletions
24
db/query/arcgis/account.go
Normal file
24
db/query/arcgis/account.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package arcgis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/table"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
func AccountFromID(ctx context.Context, org_id string) (*model.Account, error) {
|
||||
statement := table.Account.SELECT(
|
||||
table.Account.AllColumns,
|
||||
).FROM(table.Account).
|
||||
WHERE(table.Account.ID.EQ(postgres.String(org_id)))
|
||||
return db.ExecuteOne[model.Account](ctx, statement)
|
||||
}
|
||||
func AccountInsert(ctx context.Context, txn bob.Tx, m *model.Account) (*model.Account, error) {
|
||||
statement := table.Account.INSERT(table.Account.AllColumns).
|
||||
MODEL(m)
|
||||
return db.ExecuteOneTx[model.Account](ctx, txn, statement)
|
||||
}
|
||||
87
db/query/arcgis/oauth.go
Normal file
87
db/query/arcgis/oauth.go
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package arcgis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/table"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
func OAuthTokenInsert(ctx context.Context, m *model.OAuthToken) (*model.OAuthToken, error) {
|
||||
statement := table.OAuthToken.INSERT(table.OAuthToken.MutableColumns).
|
||||
MODEL(m)
|
||||
return db.ExecuteOne[model.OAuthToken](ctx, statement)
|
||||
}
|
||||
func OAuthTokenInvalidate(ctx context.Context, id int64) error {
|
||||
statement := table.OAuthToken.UPDATE().
|
||||
SET(table.OAuthToken.InvalidatedAt.SET(postgres.LOCALTIMESTAMP())).
|
||||
WHERE(table.OAuthToken.ID.EQ(postgres.Int(id)))
|
||||
return db.ExecuteNone(ctx, statement)
|
||||
}
|
||||
func OAuthTokensValid(ctx context.Context) ([]*model.OAuthToken, error) {
|
||||
statement := table.OAuthToken.SELECT(table.OAuthToken.AllColumns).
|
||||
FROM(table.OAuthToken).
|
||||
WHERE(table.OAuthToken.InvalidatedAt.IS_NULL())
|
||||
return db.ExecuteMany[model.OAuthToken](ctx, statement)
|
||||
}
|
||||
func OAuthTokenFromID(ctx context.Context, id int64) (*model.OAuthToken, error) {
|
||||
statement := table.OAuthToken.SELECT(
|
||||
table.OAuthToken.AllColumns,
|
||||
).FROM(table.OAuthToken).
|
||||
WHERE(table.OAuthToken.ID.EQ(postgres.Int(id)))
|
||||
return db.ExecuteOne[model.OAuthToken](ctx, statement)
|
||||
}
|
||||
func OAuthTokenForUser(ctx context.Context, user_id int64) (*model.OAuthToken, error) {
|
||||
statement := table.OAuthToken.SELECT(table.OAuthToken.AllColumns).
|
||||
FROM(table.OAuthToken).
|
||||
WHERE(table.OAuthToken.InvalidatedAt.IS_NULL().AND(
|
||||
table.OAuthToken.UserID.EQ(postgres.Int(user_id)),
|
||||
)).
|
||||
ORDER_BY(table.OAuthToken.Created.DESC()).
|
||||
LIMIT(1)
|
||||
return db.ExecuteOne[model.OAuthToken](ctx, statement)
|
||||
}
|
||||
func OAuthTokensForUser(ctx context.Context, user_id int64) ([]*model.OAuthToken, error) {
|
||||
statement := table.OAuthToken.SELECT(table.OAuthToken.AllColumns).
|
||||
FROM(table.OAuthToken).
|
||||
WHERE(table.OAuthToken.InvalidatedAt.IS_NULL().AND(
|
||||
table.OAuthToken.UserID.EQ(postgres.Int(user_id)),
|
||||
))
|
||||
return db.ExecuteMany[model.OAuthToken](ctx, statement)
|
||||
}
|
||||
func OAuthTokenForUserExists(ctx context.Context, user_id int64) (*bool, error) {
|
||||
statement := table.OAuthToken.SELECT(postgres.Bool(true)).
|
||||
FROM(table.OAuthToken).
|
||||
WHERE(table.OAuthToken.UserID.EQ(postgres.Int(user_id))).
|
||||
LIMIT(1)
|
||||
return db.ExecuteOne[bool](ctx, statement)
|
||||
}
|
||||
func OAuthTokenUpdateAccessToken(ctx context.Context, oauth_id int64, updates *model.OAuthToken) error {
|
||||
statement := table.OAuthToken.UPDATE(
|
||||
table.OAuthToken.AccessToken,
|
||||
table.OAuthToken.AccessTokenExpires,
|
||||
table.OAuthToken.Username,
|
||||
).MODEL(updates).
|
||||
WHERE(table.OAuthToken.ID.EQ(postgres.Int(oauth_id)))
|
||||
return db.ExecuteNone(ctx, statement)
|
||||
}
|
||||
func OAuthTokenUpdateRefreshToken(ctx context.Context, oauth_id int64, updates *model.OAuthToken) error {
|
||||
statement := table.OAuthToken.UPDATE(
|
||||
table.OAuthToken.RefreshToken,
|
||||
table.OAuthToken.RefreshTokenExpires,
|
||||
table.OAuthToken.Username,
|
||||
).MODEL(updates).
|
||||
WHERE(table.OAuthToken.ID.EQ(postgres.Int(oauth_id)))
|
||||
return db.ExecuteNone(ctx, statement)
|
||||
|
||||
}
|
||||
func OAuthTokenUpdateLicense(ctx context.Context, refresh_token string, updates *model.OAuthToken) error {
|
||||
statement := table.OAuthToken.UPDATE(
|
||||
table.OAuthToken.ArcgisID,
|
||||
table.OAuthToken.ArcgisLicenseTypeID,
|
||||
).MODEL(updates).
|
||||
WHERE(table.OAuthToken.RefreshToken.EQ(postgres.String(refresh_token)))
|
||||
return db.ExecuteNone(ctx, statement)
|
||||
}
|
||||
31
db/query/arcgis/service_feature.go
Normal file
31
db/query/arcgis/service_feature.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package arcgis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/table"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
func ServiceFeatureFromID(ctx context.Context, id string) (*model.ServiceFeature, error) {
|
||||
statement := table.ServiceFeature.SELECT(
|
||||
table.ServiceFeature.AllColumns,
|
||||
).FROM(table.ServiceFeature).
|
||||
WHERE(table.ServiceFeature.ItemID.EQ(postgres.String(id)))
|
||||
return db.ExecuteOne[model.ServiceFeature](ctx, statement)
|
||||
}
|
||||
func ServiceFeatureFromURL(ctx context.Context, url string) (*model.ServiceFeature, error) {
|
||||
statement := table.ServiceFeature.SELECT(
|
||||
table.ServiceFeature.AllColumns,
|
||||
).FROM(table.ServiceFeature).
|
||||
WHERE(table.ServiceFeature.URL.EQ(postgres.String(url)))
|
||||
return db.ExecuteOne[model.ServiceFeature](ctx, statement)
|
||||
}
|
||||
func ServiceFeatureInsert(ctx context.Context, txn bob.Tx, m *model.ServiceFeature) error {
|
||||
statement := table.ServiceMap.INSERT(table.ServiceMap.MutableColumns).
|
||||
MODEL(m)
|
||||
return db.ExecuteNoneTx(ctx, txn, statement)
|
||||
}
|
||||
31
db/query/arcgis/service_map.go
Normal file
31
db/query/arcgis/service_map.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package arcgis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/table"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
func ServiceMapFromID(ctx context.Context, id string) (*model.ServiceMap, error) {
|
||||
statement := table.ServiceMap.SELECT(
|
||||
table.ServiceMap.AllColumns,
|
||||
).FROM(table.ServiceMap).
|
||||
WHERE(table.ServiceMap.ArcgisID.EQ(postgres.String(id)))
|
||||
return db.ExecuteOne[model.ServiceMap](ctx, statement)
|
||||
}
|
||||
func ServiceMapsFromAccountID(ctx context.Context, account_id string) ([]*model.ServiceMap, error) {
|
||||
statement := table.ServiceMap.SELECT(
|
||||
table.ServiceMap.AllColumns,
|
||||
).FROM(table.ServiceMap).
|
||||
WHERE(table.ServiceMap.AccountID.EQ(postgres.String(account_id)))
|
||||
return db.ExecuteMany[model.ServiceMap](ctx, statement)
|
||||
}
|
||||
func ServiceMapInsert(ctx context.Context, txn bob.Tx, m *model.ServiceMap) error {
|
||||
statement := table.ServiceMap.INSERT(table.ServiceMap.MutableColumns).
|
||||
MODEL(m)
|
||||
return db.ExecuteNoneTx(ctx, txn, statement)
|
||||
}
|
||||
24
db/query/arcgis/user.go
Normal file
24
db/query/arcgis/user.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package arcgis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/table"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
func UserFromID(ctx context.Context, id string) (*model.User, error) {
|
||||
statement := table.User.SELECT(table.User.AllColumns).
|
||||
FROM(table.User).
|
||||
WHERE(table.User.ID.EQ(postgres.String(id)))
|
||||
return db.ExecuteOne[model.User](ctx, statement)
|
||||
}
|
||||
func UserInsert(ctx context.Context, txn bob.Tx, m *model.User) (*model.User, error) {
|
||||
statement := table.User.INSERT(table.User.MutableColumns).
|
||||
MODEL(m).
|
||||
RETURNING(table.User.AllColumns)
|
||||
return db.ExecuteOneTx[model.User](ctx, txn, statement)
|
||||
}
|
||||
22
db/query/arcgis/user_privileges.go
Normal file
22
db/query/arcgis/user_privileges.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package arcgis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/table"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
func UserPrivilegesDeleteByUserID(ctx context.Context, txn bob.Tx, id string) error {
|
||||
statement := table.User.DELETE().
|
||||
WHERE(table.User.ID.EQ(postgres.String(id)))
|
||||
return db.ExecuteNoneTx(ctx, txn, statement)
|
||||
}
|
||||
func UserPrivilegeInsert(ctx context.Context, txn bob.Tx, m *model.UserPrivilege) error {
|
||||
statement := table.UserPrivilege.INSERT(table.UserPrivilege.MutableColumns).
|
||||
MODEL(m)
|
||||
return db.ExecuteNoneTx(ctx, txn, statement)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue