### Preparing and Executing Stored Queries Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Demonstrates how to prepare, clear, and execute stored queries for reuse. Allows inspecting the built URL for a stored query. ```typescript query.select("a").where("a > 1").prepare("first").clear(); query.select("b").prepare("second"); await query.execute("first"); query.getURL("second"); // inspect the built URL ``` -------------------------------- ### Fetching Query Results in Various Formats Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Shows how to execute a query and retrieve results as an array of rows, a single row, a count, column metadata, GeoJSON, or CSV. Includes accessing response headers. ```typescript const { data, error, status } = await query.execute(); // Array of rows const { data: row } = await query.single(); // first row or null const { data: total } = await query.count(); // matching row count (number) const { data: cols } = await query.getColumns(); // [{ fieldName, dataTypeName, ... }] const { data: geojson } = await query.executeGeoJSON(); // FeatureCollection const { data: csv } = await query.executeCSV(); // raw CSV string // Response headers from the last request await query.execute(); query.headers.lastModified; query.headers.etag; ``` -------------------------------- ### Order, Group, Having, and Search Clauses Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Configure sorting with `orderBy`, aggregate data with `groupBy`, filter aggregated results with `having`, and perform full-text searches using `search`. The `withSystemFields` method includes metadata fields. ```typescript import { Order, Select, Where } from "jsr:@j3lte/soda"; query.orderBy(Order.by("created_date").desc, Order.by("agency").asc); // .asc/.desc are getters query.orderBy("created_date DESC"); // string works too query .select(Select("borough"), Select("amount").sum().as("total")) .groupBy("borough") .having(Where.gt("total", 1000)); // having needs a groupBy query.search("noise"); // full-text $q query.withSystemFields(); // include :id / :created_at / :updated_at ``` -------------------------------- ### Building Expressions with SODA Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Demonstrates how to construct arithmetic expressions for use in SODA queries. Supports basic operations like multiplication, division, and addition. ```typescript expr.mul("price", "qty"); // (price * qty) expr.div(expr.add("a", "b"), 2); // ((a + b) / 2) — also sub/mod/pow query.select(Select(expr.mul("price", "qty")).as("total")); ``` -------------------------------- ### Create a SodaQuery Instance Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Instantiate a SodaQuery client for a specific Socrata dataset. You can use the `createQueryWithDataset` helper or the `SodaQuery` class constructor. Supports typed rows by providing a Row type argument. ```typescript import { createQueryWithDataset, SodaQuery } from "jsr:@j3lte/soda"; const query = new SodaQuery("data.cityofnewyork.us").withDataset("erm2-nwe9"); // same as: const q2 = createQueryWithDataset("data.cityofnewyork.us", "erm2-nwe9"); // Typed rows: type Row = { agency: string; complaint_type: string }; const typed = new SodaQuery("data.cityofnewyork.us").withDataset("erm2-nwe9"); ``` -------------------------------- ### Construct and Execute a Full SODA Query Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Build a comprehensive SODA query using a chain of methods for selecting fields, applying filters, ordering results, and limiting the output. The `execute` method fetches the data. ```typescript import { Order, SodaQuery, Where } from "jsr:@j3lte/soda"; const { data, error, status } = await new SodaQuery("data.cityofnewyork.us") .withDataset("erm2-nwe9") .select("agency", "borough", "complaint_type") .where( Where.and( Where.like("complaint_type", "Noise%"), Where.gt("created_date", "2019-01-01T00:00:00.000"), ), ) .orderBy(Order.by("created_date").desc) .limit(10) .execute(); ``` -------------------------------- ### SodaQuery Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt The chainable query builder and HTTP client. It supports methods for selecting, filtering, grouping, ordering, limiting, searching, and executing queries. ```APIDOC ## SodaQuery ### Description The SodaQuery object acts as a chainable query builder and an HTTP client for interacting with Socrata APIs. It allows users to construct complex queries step-by-step and execute them. ### Methods - `select(...fields)`: Configures the fields to be selected in the query. - `where(expression)`: Adds a WHERE clause to the query using a Where object. - `having(expression)`: Adds a HAVING clause to the query. - `groupBy(...fields)`: Specifies fields for grouping results. - `orderBy(...fields)`: Defines the order of the results. - `limit(count)`: Sets the maximum number of results to return. - `offset(count)`: Sets the number of results to skip. - `search(query)`: Adds a search clause to the query. - `simple(query)`: Applies a simple query string. - `soql(query)`: Allows direct input of a SoQL query string. - `execute()`: Executes the query and returns a Promise for the results. - `single()`: Executes the query and returns a Promise for a single result. - `pages()`: Executes the query and returns a Promise for paginated results. - `rows()`: Executes the query and returns a Promise for all results as rows. - `executeAll()`: Executes the query and returns a Promise for all results. - `count()`: Executes a count query and returns a Promise for the count. - `getColumns()`: Retrieves the column metadata for the dataset. - `executeCSV()`: Executes the query and returns results in CSV format. - `executeGeoJSON()`: Executes the query and returns results in GeoJSON format. - `getMetaData()`: Retrieves metadata about the query execution. ``` -------------------------------- ### SodaQuery Authentication Options Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Configure authentication for your SodaQuery instance using an API token, Basic authentication (username/password), or OAuth access token. An optional third argument can be used for query options like `strict: true`. ```typescript new SodaQuery("data.cityofnewyork.us", { apiToken: "APP_TOKEN" }); // raises rate limit new SodaQuery("data.cityofnewyork.us", { username: "u", password: "p" }); // Basic new SodaQuery("data.cityofnewyork.us", { accessToken: "OAUTH" }); // OAuth new SodaQuery("data.cityofnewyork.us", {}, { strict: true }); // options arg ``` -------------------------------- ### Iterating Through Query Results with Pagination Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Illustrates methods for handling paginated results. Supports iterating over pages, individual rows, or fetching all results up to an optional maximum. ```typescript for await (const page of query.pages({ pageSize: 1000 })) { /* array per page */ } for await (const row of query.rows()) { /* one row at a time */ } const { data: all } = await query.executeAll({ max: 50000 }); // eager, optional cap ``` -------------------------------- ### SODA Select Transformations Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Utilize the `Select` helper to apply aggregate functions (sum, count, avg), string transformations (upperCase, unaccent), mathematical functions (log), date extractions, geometric operations (convexHull), and conditional logic (SelectCase) to selected fields. ```typescript import { Select, SelectCase, Where } from "jsr:@j3lte/soda"; Select("amount").sum().as("total"); // sum(amount) as total Select("name").count().as("n"); // count(name) as n Select("value").avg(); // avg(value) Select("name").upperCase(); // upper(name) Select("name").unaccent(); // unaccent(name) Select("value").log(); // ln(value) Select("created_date").dateExtractYear(); // date_extract_y(created_date) Select("the_geom").convexHull(); // convex_hull(the_geom) // Conditional case(...). Trailing ["true", ...] is the default. SelectCase( [Where.gt("score", 90), "A"], [Where.gt("score", 80), "B"], ["true", "F"], ).as("grade"); ``` -------------------------------- ### expr Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Helper functions for constructing raw expressions, including boolean logic and arithmetic operations. ```APIDOC ## expr ### Description Provides helper functions for building raw expressions within SoQL queries. This includes logical and arithmetic operations that can be safely nested. ### Boolean Operators - `and(...expressions)`: Combines expressions with a logical AND. - `or(...expressions)`: Combines expressions with a logical OR. ### Arithmetic Operators - `add(a, b)`: Addition (`+`). - `sub(a, b)`: Subtraction (`-`). - `mul(a, b)`: Multiplication (`*`). - `div(a, b)`: Division (`/`). - `mod(a, b)`: Modulo (`%`). - `pow(base, exponent)`: Exponentiation (`^`). ### Nesting Expressions can be parenthesized for safe nesting and to control the order of operations. ``` -------------------------------- ### SelectCase Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt The SelectCase object is used to construct SoQL `CASE` expressions. ```APIDOC ## SelectCase ### Description The `SelectCase` object is used to build SoQL `CASE WHEN ... THEN ... END` expressions. It takes an array of `[condition, value]` pairs. ### Usage - Provide an array of pairs, where each pair consists of a condition and its corresponding value if the condition is met. - The `CASE` expression evaluates conditions in order and returns the value associated with the first true condition. ``` -------------------------------- ### Select Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt The Select object is used to define which fields and expressions are included in the query results. ```APIDOC ## Select ### Description The `$select` builder allows for the specification of fields and expressions to be returned in the query results. It supports aliasing and aggregate functions. ### Features - **Plain Fields**: Select individual fields by their names. - **Aliases**: Use `as(aliasName)` to rename a selected field or expression. - **Aggregates**: Use functions like `count()`, `avg()`, `sum()`, `min()`, `max()`, `distinct()`, `stddev()` to perform calculations on fields. - **Functions**: Apply various numeric, text, date, and geospatial functions to fields. ``` -------------------------------- ### Field and DataType Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Represents typed field objects and Socrata data types, with details on availability. ```APIDOC ## Field and DataType ### Description This module provides tools for working with typed field objects and understanding Socrata data types. It includes documentation specific to each data type and their version availability. ### Features - **Typed Field Objects**: Define fields with specific data types. - **Socrata Data Types**: Access and reference the standard Socrata data types. - **Per-Type Documentation**: Detailed information for each data type. - **Version Availability**: Information on which versions of the Socrata API support specific data types. ``` -------------------------------- ### SODA Where Clause Filters Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Construct complex filtering conditions using the `Where` helper for equality, inequality, range checks, list membership, pattern matching, null checks, and string prefix matching. Supports combining conditions with AND/OR logic and creating filters from object literals. ```typescript import { Where } from "jsr:@j3lte/soda"; Where.eq("borough", "MANHATTAN"); // borough = 'MANHATTAN' Where.ne("status", "Closed"); // status != 'Closed' Where.gt("score", 80); // score > 80 (also gte/lt/lte) Where.between("score", 50, 100); // score between 50 and 100 Where.in("borough", "MANHATTAN", "BROOKLYN"); // borough in ('MANHATTAN','BROOKLYN') Where.notIn("status", "Closed", "Pending"); Where.like("complaint_type", "Noise%"); // complaint_type like 'Noise%' Where.isNull("closed_date"); // closed_date IS NULL Where.isNotNull("closed_date"); Where.startsWith("complaint_type", "Noise"); // starts_with(complaint_type, 'Noise') // Combine Where.and(Where.eq("borough", "BRONX"), Where.or(Where.eq("s", "Open"), Where.eq("s", "Pending"))); Where.from({ borough: "BRONX", status: "Open" }); // all AND-ed equals Where.field("score").gt(80); // bind a field once // Geospatial (Location / Point / Line / Polygon / Multi*) Where.withinBox("the_geom", 40.78, -73.98, 40.74, -73.94); Where.withinCircle("the_geom", 40.7128, -74.006, 1000); // radius meters Where.withinPolygon("the_geom", "MULTIPOLYGON (((...)))"); // WKT, longitude-first Where.intersects("the_geom", "POINT (-73.98 40.75)"); ``` -------------------------------- ### Arithmetic Expressions in SODA Queries Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Construct arithmetic expressions for use in SODA queries using the `expr` helper. Parentheses can be used for safe nesting of expressions. ```typescript import { expr, Select } from "jsr:@j3lte/soda"; ``` -------------------------------- ### Where Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt The Where object is used to build filter expressions for the `where` and `having` clauses in SodaQuery. ```APIDOC ## Where ### Description The `$where` filter builder allows for the construction of complex filtering conditions. It supports various comparison operators and logical combinations. ### Operators - `eq(value)`: Equal to. - `ne(value)`: Not equal to. - `gt(value)`: Greater than. - `gte(value)`: Greater than or equal to. - `lt(value)`: Less than. - `lte(value)`: Less than or equal to. - `isNull()`: Checks if the field is null. - `isNotNull()`: Checks if the field is not null. - `in(values)`: Checks if the field value is within a list of values. - `notIn(values)`: Checks if the field value is not within a list of values. - `like(pattern)`: Pattern matching (SQL LIKE). - `notLike(pattern)`: Negated pattern matching. - `between(min, max)`: Checks if the value is between two bounds. - `notBetween(min, max)`: Checks if the value is not between two bounds. - `and(expression)`: Combines conditions with AND. - `or(expression)`: Combines conditions with OR. - `field(fieldName)`: Specifies the field to apply the condition on. ### Geospatial Operators - `withinBox(southLatitude, westLongitude, northLatitude, eastLongitude)`: Checks if a point is within a bounding box. - `withinCircle(latitude, longitude, radius)`: Checks if a point is within a circle. - `withinPolygon(polygon)`: Checks if a point is within a polygon. - `intersects(geometry)`: Checks if a geometry intersects with another. - `startsWith(prefix)`: Checks if a string field starts with a given prefix. ``` -------------------------------- ### Typed Fields for Compile-Time Checks Source: https://raw.githubusercontent.com/j3lte/deno-soda/refs/heads/main/llms.txt Use `Field` with `DataType` to enforce type safety during query construction, preventing runtime errors like applying aggregate functions to text fields. This provides compile-time validation for field types. ```typescript import { DataType, Field, Select } from "jsr:@j3lte/soda"; Field("score", DataType.Number); query.select(Select(Field("name", DataType.Text)).as("alias")); // ok query.select(Select(Field("name", DataType.Text)).avg()); // throws: avg on Text ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.