paleolimbot opened a new pull request, #876:
URL: https://github.com/apache/arrow-adbc/pull/876

   For frameworks that use S4 (notably, DBI), slot type enforcement is useful 
when the underlying object is an external pointer. This PR adds `setOldClass()` 
calls such that you can use 
adbc_driver/adbc_database/adbc_connection/adbc_statement as slots:
   
   Before this PR:
   
   ``` r
   library(adbcdrivermanager)
   
   setClass("SomeClass",
     slots = list(
       driver = "adbc_driver",
       database = "adbc_database",
       connection = "adbc_connection",
       statement = "adbc_statement"
     )
   )
   #> Warning: undefined slot classes in definition of "SomeClass": driver(class
   #> "adbc_driver"), database(class "adbc_database"), connection(class
   #> "adbc_connection"), statement(class "adbc_statement")
   
   setMethod("initialize", "SomeClass", function(.Object, driver, ...) {
     .Object@driver <- driver
     .Object@database <- adbc_database_init(.Object@driver, ...)
     .Object@connection <- adbc_connection_init(.Object@database)
     .Object@statement <- adbc_statement_init(.Object@connection)
     .Object
   })
   
   
   new("SomeClass", adbc_driver_void())
   #> Error in (function (cl, name, valueClass) : c("assignment of an object of 
class \"adbc_driver_void\" is not valid for @'driver' in an object of class 
\"SomeClass\"; is(value, \"adbc_driver\") is not TRUE", "assignment of an 
object of class \"adbc_driver\" is not valid for @'driver' in an object of 
class \"SomeClass\"; is(value, \"adbc_driver\") is not TRUE", "assignment of an 
object of class \"adbc_xptr\" is not valid for @'driver' in an object of class 
\"SomeClass\"; is(value, \"adbc_driver\") is not TRUE")
   ```
   
   <sup>Created on 2023-07-06 with [reprex 
v2.0.2](https://reprex.tidyverse.org)</sup>
   
   After this PR:
   
   ``` r
   library(adbcdrivermanager)
   
   setClass("SomeClass",
     slots = list(
       driver = "adbc_driver",
       database = "adbc_database",
       connection = "adbc_connection",
       statement = "adbc_statement"
     )
   )
   
   setMethod("initialize", "SomeClass", function(.Object, driver, ...) {
     .Object@driver <- driver
     .Object@database <- adbc_database_init(.Object@driver, ...)
     .Object@connection <- adbc_connection_init(.Object@database)
     .Object@statement <- adbc_statement_init(.Object@connection)
     .Object
   })
   
   
   new("SomeClass", adbc_driver_void())
   #> An object of class "SomeClass"
   #> Slot "driver":
   #> <adbc_driver_void> List of 1
   #>  $ driver_init_func:Class 'adbc_driver_init_func' <externalptr> 
   #> 
   #> Slot "database":
   #> <adbc_database> <pointer: 0x14bf4c450> List of 2
   #>  $ driver :<adbc_driver_void> List of 1
   #>   ..$ driver_init_func:Class 'adbc_driver_init_func' <externalptr> 
   #>  $ options: list()
   #> 
   #> Slot "connection":
   #> <adbc_connection> <pointer: 0x14bfbbf60> List of 2
   #>  $ database:<adbc_database> <pointer: 0x14bf4c450> List of 2
   #>   ..$ driver :<adbc_driver_void> List of 1
   #>   .. ..$ driver_init_func:Class 'adbc_driver_init_func' <externalptr> 
   #>   ..$ options: list()
   #>  $ options : list()
   #> 
   #> Slot "statement":
   #> <adbc_statement> <pointer: 0x14bf93700> List of 2
   #>  $ connection:<adbc_connection> <pointer: 0x14bfbbf60> List of 2
   #>   ..$ database:<adbc_database> <pointer: 0x14bf4c450> List of 2
   #>   .. ..$ driver :<adbc_driver_void> List of 1
   #>   .. .. ..$ driver_init_func:Class 'adbc_driver_init_func' <externalptr> 
   #>   .. ..$ options: list()
   #>   ..$ options : list()
   #>  $ options   : list()
   ```
   
   <sup>Created on 2023-07-06 with [reprex 
v2.0.2](https://reprex.tidyverse.org)</sup>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to