Skip to content

Commit

Permalink
REFACTOR: Update Naming Convention
Browse files Browse the repository at this point in the history
REFACTOR: Update Naming Convention
  • Loading branch information
FlippieCoetser committed May 1, 2024
2 parents 7f65c78 + a4f56ef commit e9c69e2
Show file tree
Hide file tree
Showing 59 changed files with 1,915 additions and 1,908 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Storage
Title: Data Access Layer
Version: 0.0.1.0002
Version: 0.0.1.0003
Authors@R:
person(given = "Flippie",
family = "Coetser",
Expand All @@ -12,7 +12,7 @@ License: file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Imports:
Validate,
Environment,
Expand All @@ -27,3 +27,5 @@ Remotes:
Suggests:
testthat (>= 3.0.0),
Config/testthat/edition: 3
Depends:
R (>= 2.10)
12 changes: 12 additions & 0 deletions R/Data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Todos Dataset
#'
#' This dataset contains todos for testing the package.
#'
#' @format A data frame with 3 rows and 5 columns:
#' \describe{
#' \item{id}{Unique identifier for the todo, stored as a UUID string.}
#' \item{task}{Description of the task.}
#' \item{status}{Status of the task.}
#' }
#' @source Generated synthetic data.
"Todos"
20 changes: 10 additions & 10 deletions R/Memory.Storage.Broker.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ Memory.Storage.Broker <- \(configuration = NULL) {
tables <- list()

operations <- list()
operations[['Create.Table']] <- \(model, table) {
tables[[table]] <<- model
operations[['create.table']] <- \(fields, table) {
tables[[table]] <<- fields
return(NULL)
}
operations[['Seed.Table']] <- \(data, table) {
operations[['seed.table']] <- \(data, table) {
tables[[table]] <<- tables[[table]] |> rbind(data)
return(NULL)
}
operations[['Get.Tables']] <- \() {
operations[['get.tables']] <- \() {
tables |> names() |> (\(name) data.frame(name = name))()
}
operations[['Execute.Query']] <- \(query) {
operations[['execute.query']] <- \(query) {
return(data.frame())
}
operations[['Insert']] <- \(entity, table) {
operations[['insert']] <- \(entity, table) {
tables[[table]] <<- tables[[table]] |> rbind(entity)
return(data.frame())
}
operations[['Select']] <- \(table, fields = '*') {
operations[['select']] <- \(table, fields = '*') {
tables[[table]]
}
operations[['SelectWhereId']] <- \(id, table, fields = '*') {
operations[['select.where.Id']] <- \(id, table, fields = '*') {
tables[[table]][tables[[table]][['id']] == id,]
}
operations[['Update']] <- \(entity, table) {
operations[['update']] <- \(entity, table) {
condition <- tables[[table]][['id']] == entity[['id']]
tables[[table]][condition,] <<- entity
return(data.frame())
}
operations[['Delete']] <- \(id, table) {
operations[['delete']] <- \(id, table) {
condition <- tables[[table]][['id']] != id
tables[[table]] <<- tables[[table]][condition,]
return(data.frame())
Expand Down
24 changes: 0 additions & 24 deletions R/Memory.Storage.Exceptions.R

This file was deleted.

52 changes: 26 additions & 26 deletions R/Memory.Storage.Service.R
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
Memory.Storage.Service <- \(broker) {
validate <- Memory.Storage.Validator()

filter.tables <- \(table) broker[['Get.Tables']]() |> subset(name == table)
filter.entities <- \(entity, table) entity[['id']] |> broker[['SelectWhereId']](table)
filter.tables <- \(table) broker[['get.tables']]() |> subset(name == table)
filter.entities <- \(entity, table) entity[['id']] |> broker[['select.where.Id']](table)

services <- list()
services[['Create.Table']] <- \(model, table) {
services[['create.table']] <- \(model, table) {
model |> validate[['Model']]()
table |> validate[['Table']]()

model |> broker[['Create.Table']](table)
model |> broker[['create.table']](table)
}
services[['Seed.Table']] <- \(data, table) {
services[['seed.table']] <- \(data, table) {
data |> validate[['Data']]()
table |> validate[['Table']]()

data |> broker[['Seed.Table']](table)
data |> broker[['seed.table']](table)
}
services[['Execute.Query']] <- \(...) {
TRUE |> validate[['Not.Implemented']]()
... |> broker[['Execute.Query']]()
services[['execute.query']] <- \(...) {
TRUE |> validate[['not.implemented']]()
... |> broker[['execute.query']]()
}
services[['Add']] <- \(entity, table) {
services[['add']] <- \(entity, table) {
entity |> validate[['Entity']]()
table |> validate[['Table']]()

table |> filter.tables() |> validate[['Is.Existing.Table']](table)
entity |> filter.entities(table) |> validate[['Is.New.Entity']]()
table |> filter.tables() |> validate[['is.existing.table']](table)
entity |> filter.entities(table) |> validate[['is.new.entity']]()

entity |> broker[['Insert']](table)
entity |> broker[['insert']](table)
}
services[['Retrieve']] <- \(table, fields) {
services[['retrieve']] <- \(table, fields) {
table |> validate[['Table']]()

table |> filter.tables() |> validate[['Is.Existing.Table']](table)
table |> filter.tables() |> validate[['is.existing.table']](table)

table |> broker[['Select']](fields)
table |> broker[['select']](fields)
}
services[['RetrieveWhereId']] <- \(id, table, fields) {
services[['retrieve.where.id']] <- \(id, table, fields) {
id |> validate[['Id']]()
table |> validate[['Table']]()

table |> filter.tables() |> validate[['Is.Existing.Table']](table)
table |> filter.tables() |> validate[['is.existing.table']](table)

id |> broker[['SelectWhereId']](table, fields)
id |> broker[['select.where.Id']](table, fields)
}
services[['Modify']] <- \(entity, table) {
services[['modify']] <- \(entity, table) {
entity |> validate[['Entity']]()
table |> validate[['Table']]()

table |> filter.tables() |> validate[['Is.Existing.Table']](table)
entity |> filter.entities(table) |> validate[['Is.Existing.Entity']]()
table |> filter.tables() |> validate[['is.existing.table']](table)
entity |> filter.entities(table) |> validate[['is.existing.entity']]()

entity |> broker[['Update']](table)
entity |> broker[['update']](table)
}
services[['Remove']] <- \(id, table) {
services[['remove']] <- \(id, table) {
id |> validate[['Id']]()
table |> validate[['Table']]()

table |> filter.tables() |> validate[['Is.Existing.Table']](table)
table |> filter.tables() |> validate[['is.existing.table']](table)

id |> broker[['Delete']](table)
id |> broker[['delete']](table)
}
return(services)
}
24 changes: 24 additions & 0 deletions R/Memory.Storage.Validation.Exceptions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Memory.Storage.Validation.Exceptions <- \() {
exceptions <- list()
exceptions[['not.implemented']] <- \(invoke) {
if(invoke) {
stop('Memory.Storage: not.implemented.', call. = FALSE)
}
}
exceptions[['key.violation']] <- \(invoke) {
if(invoke) {
stop('Memory.Storage: key.violation: Duplicate Primary Key not allowed.', call. = FALSE)
}
}
exceptions[['entity.not.found']] <- \(invoke) {
if(invoke) {
stop('Memory.Storage: entity.not.found: Entity not found in storage.', call. = FALSE)
}
}
exceptions[['table.invalid']] <- \(invoke, table) {
if(invoke) {
stop('Memory.Storage: table.invalid: ', table, ' is not a valid table.', call. = FALSE)
}
}
return(exceptions)
}
52 changes: 26 additions & 26 deletions R/Memory.Storage.Validator.R
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
Memory.Storage.Validator <- \() {
exception <- Memory.Storage.Exceptions()
exception <- Memory.Storage.Validation.Exceptions()

validators <- Validate::Validator()
validators[['Model']] <- \(model) {
model |>
validators[['Is.Not.NULL']]('model') |>
validators[['Is.Data.Frame']]() |>
validators[['Is.Empty']]()
validators[['is.not.NULL']]('model') |>
validators[['is.data.frame']]() |>
validators[['is.empty']]()
}
validators[['Table']] <- \(table) {
table |>
validators[['Is.Not.NULL']]('table') |>
validators[['Is.Character']]()
validators[['is.not.NULL']]('table') |>
validators[['is.character']]()
}
validators[['Data']] <- \(data) {
data |>
validators[['Is.Not.NULL']]('data') |>
validators[['Is.Data.Frame']]() |>
validators[['Is.Not.Empty']]()
validators[['is.not.NULL']]('data') |>
validators[['is.data.frame']]() |>
validators[['is.not.empty']]()
}
validators[['Entity']] <- \(entity) {
entity |>
validators[['Is.Not.NULL']]('entity') |>
validators[['Is.Data.Frame']]() |>
validators[['Has.One.Row']]()
validators[['is.not.NULL']]('entity') |>
validators[['is.data.frame']]() |>
validators[['has.one.row']]()
}
validators[['Id']] <- \(id) {
id |>
validators[['Is.Not.NULL']]('id') |>
validators[['Is.Character']]() |>
validators[['Is.UUID']]('id')
validators[['is.not.NULL']]('id') |>
validators[['is.character']]() |>
validators[['is.UUID']]('id')
}
validators[['Not.Implemented']] <- \(input) {
input |> exception[['Not.Implemented']]()
validators[['not.implemented']] <- \(input) {
input |> exception[['not.implemented']]()
}
validators[['Is.New.Entity']] <- \(entity) {
entity |> validators[['Is.Empty']]() |>
tryCatch(error=\(...) TRUE |> exception[['Key.Violation']]())
validators[['is.new.entity']] <- \(entity) {
entity |> validators[['is.empty']]() |>
tryCatch(error=\(...) TRUE |> exception[['key.violation']]())
}
validators[['Is.Existing.Entity']] <- \(entity) {
entity |> validators[['Has.One.Row']]() |>
tryCatch(error=\(...) TRUE |> exception[['Entity.Not.Found']]())
validators[['is.existing.entity']] <- \(entity) {
entity |> validators[['has.one.row']]() |>
tryCatch(error=\(...) TRUE |> exception[['entity.not.found']]())
}
validators[['Is.Existing.Table']] <- \(table, name = NULL) {
table |> validators[['Has.One.Row']]() |>
tryCatch(error=\(...) TRUE |> exception[['Table.Invalid']](name))
validators[['is.existing.table']] <- \(table, name = NULL) {
table |> validators[['has.one.row']]() |>
tryCatch(error=\(...) TRUE |> exception[['table.invalid']](name))
}
return(validators)
}
28 changes: 14 additions & 14 deletions R/ODBC.Configuration.Broker.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
ODBC.Configuration.Broker <- \(environment = Environment::Environment()) {
exception <- ODBC.Configuration.Exceptions()
ODBC.Configuration.Broker <- \(environment = Environment::Configurator()) {
exception <- ODBC.Configuration.Validation.Exceptions()

operations <- list()
operations[['Open.Config.File']] <- \() {
environment[['Open.Config.File']]()
operations[['open.config.file']] <- \() {
environment[['open.config.file']]()
}
operations[['Get.Preset.Config']] <- \() {
operations[['get.preset.config']] <- \() {
list(
drv = odbc::odbc(),
dsn = 'DSN' |> environment[['Get.Env.Variable']](),
uid = 'UID' |> environment[['Get.Env.Variable']](),
pwd = 'PWD' |> environment[['Get.Env.Variable']]()
dsn = 'DSN' |> environment[['get.env.variable']](),
uid = 'UID' |> environment[['get.env.variable']](),
pwd = 'PWD' |> environment[['get.env.variable']]()
) |> tryCatch(error = exception[['Configuration']])
}
operations[['Get.Manual.Config']] <- \() {
operations[['get.manual.config']] <- \() {
list(
drv = odbc::odbc(),
driver = 'DRIVER' |> environment[['Get.Env.Variable']](),
server = 'SERVER' |> environment[['Get.Env.Variable']](),
database = 'DATABASE' |> environment[['Get.Env.Variable']](),
uid = 'UID' |> environment[['Get.Env.Variable']](),
pwd = 'PWD' |> environment[['Get.Env.Variable']]()
driver = 'DRIVER' |> environment[['get.env.variable']](),
server = 'SERVER' |> environment[['get.env.variable']](),
database = 'DATABASE' |> environment[['get.env.variable']](),
uid = 'UID' |> environment[['get.env.variable']](),
pwd = 'PWD' |> environment[['get.env.variable']]()
) |> tryCatch(error = exception[['Configuration']])
}
return(operations)
Expand Down
10 changes: 5 additions & 5 deletions R/ODBC.Configuration.Processor.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ODBC.Configuration.Processor <- \(service) {
processes <- list()
processes[['Open.Config.File']] <- \() {
service[['Open.Config.File']]()
processes[['open.config.file']] <- \() {
service[['open.config.file']]()
}
processes[['Get.Config']] <- \(type = 'Preset') {
processes[['get.config']] <- \(type = 'Preset') {
configuration <- list()
configuration[['Preset']] <- \() service[['Get.Preset.Config']]()
configuration[['Manual']] <- \() service[['Get.Manual.Config']]()
configuration[['Preset']] <- \() service[['get.preset.config']]()
configuration[['Manual']] <- \() service[['get.manual.config']]()
configuration[[type]]()
}
return(processes)
Expand Down
16 changes: 8 additions & 8 deletions R/ODBC.Configuration.Service.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ ODBC.Configuration.Service <- \(broker) {
validate <- ODBC.Configuration.Validator()

services <- list()
services[['Open.Config.File']] <- \() {
broker[['Open.Config.File']]()
services[['open.config.file']] <- \() {
broker[['open.config.file']]()
}
services[['Get.Preset.Config']] <- \() {
broker[['Get.Preset.Config']]() |>
validate[['Preset.Config']]()
services[['get.preset.config']] <- \() {
broker[['get.preset.config']]() |>
validate[['preset.config']]()
}
services[['Get.Manual.Config']] <- \() {
broker[['Get.Manual.Config']]() |>
validate[['Get.Manual.Config']]()
services[['get.manual.config']] <- \() {
broker[['get.manual.config']]() |>
validate[['manual.config']]()
}
return(services)
}
Loading

0 comments on commit e9c69e2

Please sign in to comment.