@@ -152,28 +152,28 @@ DRAW line MAPPING month AS x, total AS y
152152### Quick Start
153153
154154``` rust
155- use ggsql :: {prepare, reader :: DuckDBReader , writer :: VegaLiteWriter };
155+ use ggsql :: reader :: {DuckDBReader , Reader };
156+ use ggsql :: writer :: VegaLiteWriter ;
156157
157158// Create a reader
158159let reader = DuckDBReader :: from_connection_string (" duckdb://memory" )? ;
159160
160- // Prepare the visualization
161- let prepared = ggsql :: prepare (
162- " SELECT x, y FROM data VISUALISE x, y DRAW point" ,
163- & reader
161+ // Execute the ggsql query
162+ let spec = reader . execute (
163+ " SELECT x, y FROM data VISUALISE x, y DRAW point"
164164)? ;
165165
166166// Render to Vega-Lite JSON
167167let writer = VegaLiteWriter :: new ();
168- let json = prepared . render (& writer )? ;
168+ let json = spec . render (& writer )? ;
169169```
170170
171171### Core Functions
172172
173173| Function | Purpose |
174174| ------------------------ | ------------------------------------------------------ |
175- | ` prepare (query, reader) ` | Main entry point: parse, execute SQL, resolve mappings |
176- | ` render(writer) ` | Generate output (Vega-Lite JSON) from prepared data |
175+ | ` reader.execute (query) ` | Main entry point: parse, execute SQL, resolve mappings |
176+ | ` spec. render(writer)` | Generate output (Vega-Lite JSON) from Spec |
177177| ` validate(query) ` | Validate syntax + semantics, inspect query structure |
178178
179179### Key Types
@@ -188,12 +188,12 @@ let json = prepared.render(&writer)?;
188188- ` errors() ` - Validation errors
189189- ` warnings() ` - Validation warnings
190190
191- ** ` Prepared ` ** - Result of ` prepare ()` , ready for rendering:
191+ ** ` Spec ` ** - Result of ` reader.execute ()` , ready for rendering:
192192
193193- ` render(writer) ` - Generate output (Vega-Lite JSON)
194194- ` plot() ` - Resolved plot specification
195195- ` metadata() ` - Rows, columns, layer count
196- - ` warnings() ` - Validation warnings from preparation
196+ - ` warnings() ` - Validation warnings from execution
197197- ` data() ` / ` layer_data(i) ` / ` stat_data(i) ` - Access DataFrames
198198- ` sql() ` / ` visual() ` / ` layer_sql(i) ` / ` stat_sql(i) ` - Query introspection
199199
@@ -869,7 +869,7 @@ When running in Positron IDE, the extension provides enhanced functionality:
869869** Features** :
870870
871871- PyO3-based Rust bindings compiled to a native Python extension
872- - Two-stage API mirroring the Rust API: ` prepare ()` → ` render() `
872+ - Two-stage API mirroring the Rust API: ` reader.execute ()` → ` render() `
873873- DuckDB reader with DataFrame registration
874874- Custom Python reader support: any object with ` execute_sql(sql) -> DataFrame ` method
875875- Works with any narwhals-compatible DataFrame (polars, pandas, etc.)
@@ -897,20 +897,19 @@ reader = ggsql.DuckDBReader("duckdb://memory")
897897df = pl.DataFrame({" x" : [1 , 2 , 3 ], " y" : [10 , 20 , 30 ]})
898898reader.register(" data" , df)
899899
900- # Prepare visualization
901- prepared = ggsql.prepare(
902- " SELECT * FROM data VISUALISE x, y DRAW point" ,
903- reader
900+ # Execute visualization
901+ spec = reader.execute(
902+ " SELECT * FROM data VISUALISE x, y DRAW point"
904903)
905904
906905# Inspect metadata
907- print (f " Rows: { prepared .metadata()[' rows' ]} " )
908- print (f " Columns: { prepared .metadata()[' columns' ]} " )
909- print (f " SQL: { prepared .sql()} " )
906+ print (f " Rows: { spec .metadata()[' rows' ]} " )
907+ print (f " Columns: { spec .metadata()[' columns' ]} " )
908+ print (f " SQL: { spec .sql()} " )
910909
911910# Render to Vega-Lite JSON
912911writer = ggsql.VegaLiteWriter()
913- json_output = prepared .render(writer)
912+ json_output = spec .render(writer)
914913```
915914
916915** Convenience Function** (` render_altair ` ):
@@ -943,22 +942,23 @@ print(f"Errors: {validated.errors()}")
943942
944943** Classes** :
945944
946- | Class | Description |
947- | -------------------------- | -------------------------------------------- |
948- | ` DuckDBReader(connection) ` | Database reader with DataFrame registration |
949- | ` VegaLiteWriter() ` | Vega-Lite JSON output writer |
950- | ` Validated ` | Result of ` validate() ` with query inspection |
951- | ` Prepared ` | Result of ` prepare ()` , ready for rendering |
945+ | Class | Description |
946+ | -------------------------- | ------------------------------------------------ |
947+ | ` DuckDBReader(connection) ` | Database reader with DataFrame registration |
948+ | ` VegaLiteWriter() ` | Vega-Lite JSON output writer |
949+ | ` Validated ` | Result of ` validate() ` with query inspection |
950+ | ` Spec ` | Result of ` reader.execute ()` , ready for rendering |
952951
953952** Functions** :
954953
955- | Function | Description |
956- | ------------------------ | ------------------------------------------------- |
957- | ` validate(query) ` | Syntax/semantic validation with query inspection |
958- | ` prepare(query, reader) ` | Full preparation (reader can be native or custom) |
959- | ` render_altair(df, viz) ` | Convenience: render DataFrame to Altair chart |
954+ | Function | Description |
955+ | -------------------------- | ------------------------------------------------- |
956+ | ` validate(query) ` | Syntax/semantic validation with query inspection |
957+ | ` reader.execute(query) ` | Execute ggsql query, return Spec |
958+ | ` execute(query, reader) ` | Execute with custom reader (bridge path) |
959+ | ` render_altair(df, viz) ` | Convenience: render DataFrame to Altair chart |
960960
961- ** Prepared Object Methods** :
961+ ** Spec Methods** :
962962
963963| Method | Description |
964964| ---------------- | -------------------------------------------- |
@@ -988,9 +988,9 @@ class MyReader:
988988 def execute_sql (self , sql : str ) -> pl.DataFrame:
989989 return pl.DataFrame({" x" : [1 , 2 , 3 ], " y" : [10 , 20 , 30 ]})
990990
991- # Use custom reader with prepare ()
991+ # Use custom reader with ggsql.execute ()
992992reader = MyReader()
993- prepared = ggsql.prepare (
993+ spec = ggsql.execute (
994994 " SELECT * FROM data VISUALISE x, y DRAW point" ,
995995 reader
996996)
0 commit comments