3
0

Remove partial-updates from store definitons

This commit is contained in:
Denis Arh 2020-08-16 15:18:50 +02:00
parent 5419db42ba
commit d13f222679
6 changed files with 16 additions and 53 deletions

View File

@ -28,12 +28,6 @@ lookups:
It returns compose namespace even if deleted
partialUpdates:
- name: delete
set: { DeletedAt: now() }
- name: undelete
set: { DeletedAt: nil }
rdbms:
alias: cns
table: compose_namespace

View File

@ -8,7 +8,6 @@ types:
singular: Credentials
plural: Credentials
fields:
- { field: ID }
- { field: OwnerID }
@ -32,12 +31,6 @@ lookups:
search:
disablePaging: true
partialUpdates:
- name: delete
set: { DeletedAt: now() }
- name: undelete
set: { DeletedAt: nil }
rdbms:
alias: crd
table: sys_credentials

View File

@ -66,7 +66,7 @@ func (s Store) LookupCredentialsByID(ctx context.Context, id uint64) (*types.Cre
})
}
// CreateCredentials creates one or more rows in sys_credentials table
// CreateCredentials creates one or more rows in credentials table
func (s Store) CreateCredentials(ctx context.Context, rr ...*types.Credentials) error {
if len(rr) == 0 {
return nil
@ -84,12 +84,12 @@ func (s Store) CreateCredentials(ctx context.Context, rr ...*types.Credentials)
})
}
// UpdateCredentials updates one or more existing rows in sys_credentials
// UpdateCredentials updates one or more existing rows in credentials
func (s Store) UpdateCredentials(ctx context.Context, rr ...*types.Credentials) error {
return s.PartialUpdateCredentials(ctx, nil, rr...)
}
// PartialUpdateCredentials updates one or more existing rows in sys_credentials
// PartialUpdateCredentials updates one or more existing rows in credentials
//
// It wraps the update into transaction and can perform partial update by providing list of updatable columns
func (s Store) PartialUpdateCredentials(ctx context.Context, onlyColumns []string, rr ...*types.Credentials) error {
@ -112,7 +112,7 @@ func (s Store) PartialUpdateCredentials(ctx context.Context, onlyColumns []strin
})
}
// RemoveCredentials removes one or more rows from sys_credentials table
// RemoveCredentials removes one or more rows from credentials table
func (s Store) RemoveCredentials(ctx context.Context, rr ...*types.Credentials) error {
if len(rr) == 0 {
return nil
@ -130,17 +130,17 @@ func (s Store) RemoveCredentials(ctx context.Context, rr ...*types.Credentials)
})
}
// RemoveCredentialsByID removes row from the sys_credentials table
// RemoveCredentialsByID removes row from the credentials table
func (s Store) RemoveCredentialsByID(ctx context.Context, ID uint64) error {
return ExecuteSqlizer(ctx, s.DB(), s.Delete(s.CredentialsTable("crd")).Where(squirrel.Eq{s.preprocessColumn("crd.id", ""): s.preprocessValue(ID, "")}))
}
// TruncateCredentials removes all rows from the sys_credentials table
// TruncateCredentials removes all rows from the credentials table
func (s Store) TruncateCredentials(ctx context.Context) error {
return Truncate(ctx, s.DB(), s.CredentialsTable())
}
// ExecUpdateCredentials updates all matched (by cnd) rows in sys_credentials with given data
// ExecUpdateCredentials updates all matched (by cnd) rows in credentials with given data
func (s Store) ExecUpdateCredentials(ctx context.Context, cnd squirrel.Sqlizer, set store.Payload) error {
return ExecuteSqlizer(ctx, s.DB(), s.Update(s.CredentialsTable("crd")).Where(cnd).SetMap(set))
}
@ -199,7 +199,7 @@ func (Store) CredentialsTable(aa ...string) string {
alias = " AS " + aa[0]
}
return "sys_credentials" + alias
return "credentials" + alias
}
// CredentialsColumns returns all defined table columns

View File

@ -107,7 +107,7 @@ func (s Store) LookupUserByUsername(ctx context.Context, username string) (*type
})
}
// CreateUser creates one or more rows in sys_user table
// CreateUser creates one or more rows in users table
func (s Store) CreateUser(ctx context.Context, rr ...*types.User) error {
if len(rr) == 0 {
return nil
@ -125,12 +125,12 @@ func (s Store) CreateUser(ctx context.Context, rr ...*types.User) error {
})
}
// UpdateUser updates one or more existing rows in sys_user
// UpdateUser updates one or more existing rows in users
func (s Store) UpdateUser(ctx context.Context, rr ...*types.User) error {
return s.PartialUpdateUser(ctx, nil, rr...)
}
// PartialUpdateUser updates one or more existing rows in sys_user
// PartialUpdateUser updates one or more existing rows in users
//
// It wraps the update into transaction and can perform partial update by providing list of updatable columns
func (s Store) PartialUpdateUser(ctx context.Context, onlyColumns []string, rr ...*types.User) error {
@ -153,7 +153,7 @@ func (s Store) PartialUpdateUser(ctx context.Context, onlyColumns []string, rr .
})
}
// RemoveUser removes one or more rows from sys_user table
// RemoveUser removes one or more rows from users table
func (s Store) RemoveUser(ctx context.Context, rr ...*types.User) error {
if len(rr) == 0 {
return nil
@ -171,17 +171,17 @@ func (s Store) RemoveUser(ctx context.Context, rr ...*types.User) error {
})
}
// RemoveUserByID removes row from the sys_user table
// RemoveUserByID removes row from the users table
func (s Store) RemoveUserByID(ctx context.Context, ID uint64) error {
return ExecuteSqlizer(ctx, s.DB(), s.Delete(s.UserTable("usr")).Where(squirrel.Eq{s.preprocessColumn("usr.id", ""): s.preprocessValue(ID, "")}))
}
// TruncateUsers removes all rows from the sys_user table
// TruncateUsers removes all rows from the users table
func (s Store) TruncateUsers(ctx context.Context) error {
return Truncate(ctx, s.DB(), s.UserTable())
}
// ExecUpdateUsers updates all matched (by cnd) rows in sys_user with given data
// ExecUpdateUsers updates all matched (by cnd) rows in users with given data
func (s Store) ExecUpdateUsers(ctx context.Context, cnd squirrel.Sqlizer, set store.Payload) error {
return ExecuteSqlizer(ctx, s.DB(), s.Update(s.UserTable("usr")).Where(cnd).SetMap(set))
}
@ -241,7 +241,7 @@ func (Store) UserTable(aa ...string) string {
alias = " AS " + aa[0]
}
return "sys_user" + alias
return "users" + alias
}
// UserColumns returns all defined table columns

View File

@ -26,12 +26,6 @@ lookups:
It returns attachment even if deleted
partialUpdates:
- name: delete
set: { DeletedAt: now() }
- name: undelete
set: { DeletedAt: nil }
rdbms:
alias: att
table: sys_attachment

View File

@ -43,24 +43,6 @@ lookups:
It returns only valid users (not deleted, not suspended)
partialUpdates:
- name: delete
set: { DeletedAt: now() }
description: |-
deletes user
- name: undelete
set: { DeletedAt: nil }
description: |-
undeletes user
- name: suspend
set: { SuspendedAt: now() }
description: |-
suspends user
- name: unsuspend
set: { SuspendedAt: nil }
description: |-
unsuspends user
rdbms:
alias: usr
table: sys_user