~hrbrmstr/pgcidr

b2a0a07250260b905ca8d8c20ac3224c58cf53b0 — hrbrmstr 7 months ago 03f60d0 master
pgcon vs con
M DESCRIPTION => DESCRIPTION +1 -1
@@ 27,4 27,4 @@ Imports:
    glue,
    readr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1

M R/create-cidr-tbl.R => R/create-cidr-tbl.R +6 -6
@@ 45,7 45,7 @@
create_cidr_lookup_table <- function(pgcon, tbl_name, drop=FALSE, xdf,
                                     entity_col="entity", cidr_col="cidr") {

  stopifnot(inherits(con, "PostgreSQL"))
  stopifnot(inherits(pgcon, "PostgreSQL"))

  tbl_name <- tbl_name[1]
  idx_name <- ac(gg("{tbl_name}_idx"))


@@ 69,14 69,14 @@ create_cidr_lookup_table <- function(pgcon, tbl_name, drop=FALSE, xdf,
  }

  if (drop) {
    dbExecute(con, ac(gg("DROP TABLE IF EXISTS {tbl_name}")))
    dbExecute(con, ac(gg("DROP INDEX IF EXISTS {idx_name}")))
    dbExecute(pgcon, ac(gg("DROP TABLE IF EXISTS {tbl_name}")))
    dbExecute(pgcon, ac(gg("DROP INDEX IF EXISTS {idx_name}")))
  }

  dbExecute(con, ac(gg("CREATE TABLE {tbl_name}({entity_col} text not null, {cidr_col} ip4r primary key)")))
  dbExecute(pgcon, ac(gg("CREATE TABLE {tbl_name}({entity_col} text not null, {cidr_col} ip4r primary key)")))

  dbExecute(con, ac(gg("COPY {tbl_name} FROM '{tf}' WITH (format csv, header)")))
  dbExecute(con, ac(gg("CREATE INDEX {idx_name} ON {tbl_name} USING gist({cidr_col})")))
  dbExecute(pgcon, ac(gg("COPY {tbl_name} FROM '{tf}' WITH (format csv, header)")))
  dbExecute(pgcon, ac(gg("CREATE INDEX {idx_name} ON {tbl_name} USING gist({cidr_col})")))

  invisible(NULL)


M R/create-ip-tbl.R => R/create-ip-tbl.R +6 -6
@@ 40,7 40,7 @@
#' }
create_ip_source_table <- function(pgcon, tbl_name, drop=FALSE, xdf, ip_col = "ip") {

  stopifnot(inherits(con, "PostgreSQL"))
  stopifnot(inherits(pgcon, "PostgreSQL"))

  tbl_name <- tbl_name[1]
  idx_name <- ac(gg("{tbl_name}_idx"))


@@ 64,14 64,14 @@ create_ip_source_table <- function(pgcon, tbl_name, drop=FALSE, xdf, ip_col = "i

  if (drop) {

    dbExecute(con, ac(gg("DROP TABLE IF EXISTS {tbl_name}")))
    dbExecute(con, ac(gg("DROP INDEX IF EXISTS {idx_name}")))
    dbExecute(pgcon, ac(gg("DROP TABLE IF EXISTS {tbl_name}")))
    dbExecute(pgcon, ac(gg("DROP INDEX IF EXISTS {idx_name}")))

  }
  dbExecute(con, ac(gg("CREATE TABLE {tbl_name}({ip_col} ip4 not null)")))
  dbExecute(pgcon, ac(gg("CREATE TABLE {tbl_name}({ip_col} ip4 not null)")))

  dbExecute(con, ac(gg("COPY {tbl_name} FROM '{tf}' WITH (format csv, header)")))
  dbExecute(con, ac(gg("CREATE INDEX {idx_name} ON {tbl_name}({ip_col})")))
  dbExecute(pgcon, ac(gg("COPY {tbl_name} FROM '{tf}' WITH (format csv, header)")))
  dbExecute(pgcon, ac(gg("CREATE INDEX {idx_name} ON {tbl_name}({ip_col})")))

  invisible(NULL)


M R/find-ips-in-cidrs.R => R/find-ips-in-cidrs.R +2 -2
@@ 39,7 39,7 @@
find_ips_in_cidrs <- function(pgcon, ip_tbl, cidr_tbl,
                              ip_col = "ip", cidr_col = "cidr") {

  stopifnot(inherits(con, "PostgreSQL"))
  stopifnot(inherits(pgcon, "PostgreSQL"))

  ip_tbl <- ip_tbl[1]
  cidr_tbl <- cidr_tbl[1]


@@ 47,7 47,7 @@ find_ips_in_cidrs <- function(pgcon, ip_tbl, cidr_tbl,
  cidr_col <- cidr_col[1]

  DBI::dbGetQuery(
    con,
    pgcon,
    ac(gg("
SELECT
  *

M R/macos-setup.R => R/macos-setup.R +1 -1
@@ 23,7 23,7 @@
#'
#' ```shell
#' $ initdb DATA_PATH  -E utf8
#' $ pg_ctl -D /Volumes/otg/postgres -l logfile start
#' $ pg_ctl -D /path/to/postgres -l logfile start
#' ```
#'
#' Make sure it's running

M man/macos_postgresql_setup_with_ip4r.Rd => man/macos_postgresql_setup_with_ip4r.Rd +1 -1
@@ 20,7 20,7 @@ $ brew install petere/postgresql/postgresql-common
}\if{html}{\out{</div>}}

Initialize the DB and start PG\if{html}{\out{<div class="shell">}}\preformatted{$ initdb DATA_PATH  -E utf8
$ pg_ctl -D /Volumes/otg/postgres -l logfile start
$ pg_ctl -D /path/to/postgres -l logfile start
}\if{html}{\out{</div>}}

Make sure it's running\if{html}{\out{<div class="shell">}}\preformatted{$ ps -ef | grep postgr