Tables we use will be characterise by one column which will be the primary_id or the rowname of the column. This is an incremental integer number of the database.
library(DBI) library(dplyr, warn.conflicts = F) library(RSQLite) library(tblCrud)
con <- dbConnect(drv=dbDriver("SQLite"), con =":memory:") tablename <- "sql_iris" bool_return <- crud_create(con, iris, tablename)
This is the content of the table:
dbReadTable(con, tablename) %>% tail
Grab a small subset, which work on:
df <- dbGetQuery(con, paste("select * from", tablename, " where Species == 'setosa' limit 10" )) df
Modify this subset:
df_1 <- df %>% mutate(Petal.Width = 50)
Add new lines to this subset:
new_line<- tribble( ~Sepal.Length, ~Sepal.Width, ~Petal.Length, ~Petal.Width, ~Species, 10, 3.5, 14, 20, "new_species" ) new_df <- bind_rows(new_line, df_1) head(new_df)
Now synchronize this subset on database:
crud_sync(con, new_df, tablename) dbReadTable(con, tablename) %>% tail
At the moment it is tested only with SQLite, but the SQL code used should be enought generic to work also on MySQL.
Tables we use will be characterise by one column which will be the primary_id or the rowname of the column. The type of this variable is string
, factor
or integer
.
The second kind of id is the incremental integer number of the database: the incremental_id. This is necessary only in case more than one user access to the database and if the user wants to change a primary_id without lose the connection with the database.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.