The fundamental way to communicate with database tables.
Details
This class is a representation of a database table. It is the way that you can access data (e.g. `tbl()`), manipulate data (e.g. `insert_data`, `upsert_data`), and manipulate structural aspects of the database table (e.g. `add_indexes`, `drop_indexes`).
Public fields
dbconnection
Database connection.
dbconfig
Configuration details of the database.
table_name
Name of the table in the database.
table_name_short_for_mssql_fully_specified_for_postgres
Fully specified name of the table in the database (e.g. \[db\].\[dbo\].\[table_name\]).
table_name_short_for_mssql_fully_specified_for_postgres_text
Fully specified name of the table in the database (e.g. \[db\].\[dbo\].\[table_name\]).
table_name_fully_specified
Fully specified name of the table in the database (e.g. \[db\].\[dbo\].\[table_name\]).
table_name_fully_specified_text
Fully specified name of the table in the database (e.g. \[db\].\[dbo\].\[table_name\]) as a text string.
field_types
The types of each column in the database table (INTEGER, DOUBLE, TEXT, BOOLEAN, DATE, DATETIME).
field_types_with_length
The same as
field_types
but with(100)
added to the end of all TEXT fields.keys
The combination of variables that uniquely identify each row in the database.
keys_with_length
The same as
keys
but with(100)
added to the end of all TEXT fields.indexes
A named list of vectors (generally "ind1", "ind2", etc.) that improves the speed of data retrieval operations on a database table.
validator_field_contents
A function that validates the data before it is inserted into the database.
load_folder
A temporary folder that is used to write data to before inserting into the database.
censors
A named list of censors.
Methods
Method new()
Create a new DBTable_v9 object.
Usage
DBTable_v9$new(
dbconfig,
table_name,
field_types,
keys,
indexes = NULL,
validator_field_types = validator_field_types_blank,
validator_field_contents = validator_field_contents_blank
)
Arguments
dbconfig
Configuration details of the database (driver, server, port, db, schema, user, password, trusted_connection, sslmode, role_create_table).
table_name
Name of the table in the database.
field_types
The types of each column in the database table (INTEGER, DOUBLE, TEXT, BOOLEAN, DATE, DATETIME).
keys
The combination of these variables uniquely identifies each row of data in the table.
indexes
A named list of vectors (generally "ind1", "ind2", etc.) that improves the speed of data retrieval operations on a database table.
validator_field_types
A function that validates the
field_types
before the DB schema is created.validator_field_contents
A function that validates the data before it is inserted into the database.
Method upsert_data()
Upserts data into the database table
Usage
DBTable_v9$upsert_data(
newdata,
drop_indexes = names(self$indexes),
verbose = TRUE
)
Method drop_rows_where()
Drops rows in the database table according to the SQL condition.
Method drop_all_rows_and_then_upsert_data()
Drops all rows in the database table and then upserts data.
Usage
DBTable_v9$drop_all_rows_and_then_upsert_data(
newdata,
drop_indexes = names(self$indexes),
verbose = TRUE
)
Method drop_all_rows_and_then_insert_data()
Drops all rows in the database table and then inserts data.
Method print_dplyr_select()
Prints a template dplyr::select call that you can easily copy/paste for all your variables.
Method confirm_indexes()
Confirms that the names and number of indexes in the database are the same as in the R code. Does not confirm the contents of the indexes!
Method nrow()
Gets the number of rows in the database table