pub struct Table {
pub name: &'static str,
pub columns: &'static [Column],
pub csv: &'static str,
}Expand description
A table in the Foodmart data set.
Fields§
§name: &'static strThe table name, and also the base name of its CSV file.
columns: &'static [Column]The table’s columns, in CSV column order.
csv: &'static strThe contents of the table’s CSV file, including the header row.
Implementations§
Source§impl Table
impl Table
Sourcepub fn column_names(&self) -> Vec<&'static str>
pub fn column_names(&self) -> Vec<&'static str>
Returns the table’s column names, in CSV column order.
Sourcepub fn header(&self) -> Vec<Cow<'static, str>>
pub fn header(&self) -> Vec<Cow<'static, str>>
Returns the header row of the CSV file, as field names.
This is always equal to Table::column_names; the crate’s
tests check that it is.
Sourcepub fn rows(&self) -> Rows ⓘ
pub fn rows(&self) -> Rows ⓘ
Returns the table’s data rows. The header row is skipped.
An empty field represents SQL NULL, and is yielded as an empty
string; consult Column::not_null to tell an empty string
from a null.
Sourcepub fn create_table_sql(&self) -> String
pub fn create_table_sql(&self) -> String
Returns a CREATE TABLE statement for the table, with
identifiers quoted using the SQL standard double-quote.
let table = foodmart_data::find("days").unwrap();
assert_eq!(
table.create_table_sql(),
r#"CREATE TABLE "days" ("day" INTEGER NOT NULL, "week_day" VARCHAR(30) NOT NULL)"#);Sourcepub fn insert_sql(&self, row: &[Cow<'_, str>]) -> String
pub fn insert_sql(&self, row: &[Cow<'_, str>]) -> String
Returns an INSERT statement for one row, as literal SQL.
Values of character, date and timestamp columns are quoted;
numeric and boolean values are not; an empty field becomes
NULL.
§Panics
Panics if row does not have one value per column.