tables

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLDialect = 0
	EgoDialect = 1
)
View Source
const (
	SQLPseudoTable = "@sql"
)
View Source
const UnexpectedNilPointerError = "Unexpected nil database object pointer"

Variables

This section is empty.

Functions

func Authorized

func Authorized(sessionID int32, db *sql.DB, user string, table string, operations ...string) bool

Authorized uses the database located in the the Ego tables database to determine if the proposed operation is permitted for the given table.

The permissions string for the table and user is read, if it exists, must contain the given permission.

func CreateTablePermissions

func CreateTablePermissions(sessionID int32, db *sql.DB, user, table string, permissions ...string) bool

CreateTablePermissions creates a row for the permissions data for a given user and named table, with the permissions enumerated as the last parameters.

func DeletePermissions

func DeletePermissions(user string, hasAdminPermission bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

DeletePermissions deletes one or permissions records for a given username and table. The permissions data is deleted completely, which means this table will only be visible to admin users.

func DeleteRows

func DeleteRows(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

DeleteRows deletes rows from a table. If no filter is provided, then all rows are deleted and the tale is empty. If filter(s) are applied, only the matching rows are deleted. The function returns the number of rows deleted.

func DeleteTable

func DeleteTable(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

DeleteTable will delete a database table from the user's schema.

func GrantPermissions

func GrantPermissions(user string, hasAdminPermission bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

GrantPermissions is used to grant and revoke permissions. The Request must be a JSON array of strings, each of which is a permission to be granted or revoked. The permissions is revoked if it starts with a "-" character, else it is granted. You must be the owner of the table or an admin user to perform this operation.

func InsertAbstractRows

func InsertAbstractRows(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

InsertRows updates the rows (specified by a filter clause as needed) with the data from the payload.

func InsertRows

func InsertRows(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

InsertRows updates the rows (specified by a filter clause as needed) with the data from the payload.

func ListTables

func ListTables(user string, isAdmin bool, sessionID int32, w http.ResponseWriter, r *http.Request)

ListTables will list all the tables for the given user.

func OpenDB

func OpenDB(sessionID int32, user, table string) (db *sql.DB, err error)

func ReadAbstractRows

func ReadAbstractRows(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

ReadRows reads the data for a given table, and returns it as an array of structs for each row, with the struct tag being the column name. The query can also specify filter, sort, and column query parameters to refine the read operation.

func ReadAllPermissions

func ReadAllPermissions(db *sql.DB, sessionID int32, w http.ResponseWriter, r *http.Request)

ReadAllPermissions reads all permissions for all tables. By default it is for all users, though you can use the ?user= parameter to specify permissions for a given user for all tables. The result is an array of permissions objects for each permutation of owner and table name visible to the user.

func ReadPermissions

func ReadPermissions(user string, hasAdminPermission bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

ReadPermissions reads the permissions data for a specific table. This operation requires either ownership of the table or admin privileges. The response is a Permission object for the given user and table.

func ReadRows

func ReadRows(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

ReadRows reads the data for a given table, and returns it as an array of structs for each row, with the struct tag being the column name. The query can also specify filter, sort, and column query parameters to refine the read operation.

func ReadTable

func ReadTable(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

ReadTable reads the metadata for a given table, and returns it as an array of column names and types.

func RemoveTablePermissions

func RemoveTablePermissions(sessionID int32, db *sql.DB, table string) bool

RemoveTablePermissions updates the permissions data to remove references to the named table.

func SQLTransaction

func SQLTransaction(r *http.Request, w http.ResponseWriter, sessionID int32, user string)

func TableCreate

func TableCreate(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

TableCreate creates a new table based on the JSON payload, which must be an array of DBColumn objects, defining the characteristics of each column in the table. If the table name is the special name "@sql" the payload instead is assumed to be a JSON-encoded string containing arbitrary SQL to exectue. Only an admin user can use the "@sql" table name.

func TablesHandler

func TablesHandler(w http.ResponseWriter, r *http.Request)

func Transaction

func Transaction(user string, isAdmin bool, sessionID int32, w http.ResponseWriter, r *http.Request)

DeleteRows deletes rows from a table. If no filter is provided, then all rows are deleted and the tale is empty. If filter(s) are applied, only the matching rows are deleted. The function returns the number of rows deleted.

func UpdateAbstractRows

func UpdateAbstractRows(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

UpdateRows updates the rows (specified by a filter clause as needed) with the data from the payload.

func UpdateRows

func UpdateRows(user string, isAdmin bool, tableName string, sessionID int32, w http.ResponseWriter, r *http.Request)

UpdateRows updates the rows (specified by a filter clause as needed) with the data from the payload.

Types

type TXError

type TXError struct {
	Condition string `json:"condition"`
	Status    int    `json:"status"`
	Message   string `json:"msg"`
}

type TxOperation

type TxOperation struct {
	Opcode     string                 `json:"operation"`
	Table      string                 `json:"table,omitempty"`
	Filters    []string               `json:"filters,omitempty"`
	Columns    []string               `json:"columns,omitempty"`
	EmptyError bool                   `json:"emptyError,omitempty"`
	Data       map[string]interface{} `json:"data,omitempty"`
	Errors     []TXError              `json:"errors,omitempty"`
	SQL        string                 `json:"sql,omitempty"`
}

This defines a single operation performed as part of a transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL