Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Dec 15, 2023
1 parent 302df25 commit 730c834
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
5 changes: 3 additions & 2 deletions R/edit_db_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ edit_db_config <- function() {
#' @importFrom purrr `%||%`
#' @export
get_dbInfo <- function(name = NULL) {
config <- yaml::read_yaml("~/.db.yml")
if (file.exists(config)) {
f = normalizePath("~/.db.yml")
if (file.exists(f)) {
config <- yaml::read_yaml(f)
name <- name %||% names(config)[1]
if (name == "all") config else config[[name]]
} else {
Expand Down
10 changes: 0 additions & 10 deletions scripts/database/test-db_perm.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ con_mariadb = open_mariadb(dbinfo, 1)
con <- open_mariadb()
```

```{r}
table = tbl(con, "China_Mete2000_hourly_2020_2022")
system.time({
d <- table |>
filter(site == 50136) |>
collect()
})
```

## 测试基础命令

```{r}
Expand Down
14 changes: 10 additions & 4 deletions scripts/test_dbase.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
library(dplyr)
library(duckdb)
# dbinfo$hourly_2020_2022

db = dbase$new()
## hourly气象数据
dbinfo <- get_dbInfo("duckdb")
f = dbinfo$hourly_2020_2022$db
db = dbase$new(f)
db

d <- db$read_data(site == 50246L) # first time about 20s, 16s可以读进来所有数据
d <- db$read_data(site == 50246L) # 0.6s
# db$close(force=TRUE)
# db$close()

## 径流数据
f = "z:/DATA/China/ChinaRunoff_latest/ChinaWater_latest/back_up/ChinaWater_river (20200603H22-20210116H14).db"
db <- dbase$new(f)
db$read_table()
db
db$read_data(stcd == 10701210L)
3 changes: 2 additions & 1 deletion tests/testthat/test-write_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ test_write_table <- function(f = "hello.db") {
db$write_table(mtcars, "mtcars", append = TRUE)
d = db$read_table("mtcars")
expect_equal(nrow(d), 2 * nrow(mtcars))

print(db)

db$close()
file.remove(f)
}
Expand Down

0 comments on commit 730c834

Please sign in to comment.