Move internal terminology to tables/rows

This commit is contained in:
Jonathan Turner
2019-09-06 04:23:42 +12:00
parent 0a9897c5ca
commit dcd97b6346
70 changed files with 220 additions and 219 deletions

View File

@ -1,4 +1,4 @@
use crate::object::Value;
use crate::data::Value;
#[derive(Debug)]
pub enum LogLevel {}

View File

@ -1,7 +1,7 @@
use crate::context::{SourceMap, SpanSource};
use crate::errors::ShellError;
use crate::evaluate::Scope;
use crate::object::Value;
use crate::data::Value;
use crate::parser::hir;
use crate::parser::{registry, ConfigDeserializer};
use crate::prelude::*;

View File

@ -2,7 +2,7 @@ use crate::prelude::*;
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{config, Value};
use crate::data::{config, Value};
use crate::parser::hir::SyntaxType;
use crate::parser::registry::{self};
use std::iter::FromIterator;
@ -55,7 +55,7 @@ pub fn config(
}: ConfigArgs,
RunnableContext { name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
let mut result = crate::object::config::config(name)?;
let mut result = crate::data::config::config(name)?;
if let Some(v) = get {
let key = v.to_string();
@ -74,7 +74,7 @@ pub fn config(
config::write_config(&result)?;
return Ok(stream![Tagged::from_simple_spanned_item(
Value::Object(result.into()),
Value::Row(result.into()),
value.span()
)]
.from_input_stream());
@ -90,7 +90,7 @@ pub fn config(
config::write_config(&result)?;
return Ok(stream![Tagged::from_simple_spanned_item(
Value::Object(result.into()),
Value::Row(result.into()),
span
)]
.from_input_stream());
@ -123,9 +123,9 @@ pub fn config(
)));
}
let obj = VecDeque::from_iter(vec![Value::Object(result.into()).simple_spanned(v.span())]);
let obj = VecDeque::from_iter(vec![Value::Row(result.into()).simple_spanned(v.span())]);
return Ok(obj.from_input_stream());
}
return Ok(vec![Value::Object(result.into()).simple_spanned(name)].into());
return Ok(vec![Value::Row(result.into()).simple_spanned(name)].into());
}

View File

@ -1,5 +1,5 @@
use crate::errors::ShellError;
use crate::object::{Dictionary, Value};
use crate::data::{Dictionary, Value};
use crate::prelude::*;
use chrono::{DateTime, Local, Utc};
@ -17,9 +17,7 @@ impl WholeStreamCommand for Date {
}
fn signature(&self) -> Signature {
Signature::build("date")
.switch("utc")
.switch("local")
Signature::build("date").switch("utc").switch("local")
}
fn usage(&self) -> &str {
@ -72,7 +70,7 @@ where
Tagged::from_simple_spanned_item(Value::string(format!("{}", tz)), span),
);
Tagged::from_simple_spanned_item(Value::Object(Dictionary::from(indexmap)), span)
Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span)
}
pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {

View File

@ -1,7 +1,7 @@
use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::data::Value;
use crate::errors::ShellError;
use crate::object::Value;
use crate::parser::hir::SyntaxType;
use crate::parser::registry::Signature;
use crate::prelude::*;
@ -106,7 +106,7 @@ fn run(
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec {
match res {
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
for l in list {
yield Ok(ReturnSuccess::Value(l));
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ExpectedRange;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use bson::{decode_document, spec::BinarySubtype, Bson};
use std::str::FromStr;
@ -48,7 +48,7 @@ fn convert_bson_value_to_nu_value(
Ok(match v {
Bson::FloatingPoint(n) => Value::Primitive(Primitive::from(*n)).tagged(tag),
Bson::String(s) => Value::Primitive(Primitive::String(String::from(s))).tagged(tag),
Bson::Array(a) => Value::List(bson_array(a, tag)?).tagged(tag),
Bson::Array(a) => Value::Table(bson_array(a, tag)?).tagged(tag),
Bson::Document(doc) => {
let mut collected = TaggedDictBuilder::new(tag);
for (k, v) in doc.iter() {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use csv::ReaderBuilder;
@ -16,8 +16,7 @@ impl WholeStreamCommand for FromCSV {
}
fn signature(&self) -> Signature {
Signature::build("from-csv")
.switch("headerless")
Signature::build("from-csv").switch("headerless")
}
fn usage(&self) -> &str {
@ -78,7 +77,7 @@ pub fn from_csv_string_to_value(
}
}
Ok(Tagged::from_item(Value::List(rows), tag))
Ok(Tagged::from_item(Value::Table(rows), tag))
}
fn from_csv(
@ -116,7 +115,7 @@ fn from_csv(
match from_csv_string_to_value(concat_string, skip_headers, name_span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use std::collections::HashMap;
@ -94,7 +94,7 @@ fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
match from_ini_string_to_value(concat_string, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromJSON;
@ -15,8 +15,7 @@ impl WholeStreamCommand for FromJSON {
}
fn signature(&self) -> Signature {
Signature::build("from-json")
.switch("objects")
Signature::build("from-json").switch("objects")
}
fn usage(&self) -> &str {
@ -44,7 +43,7 @@ fn convert_json_value_to_nu_value(v: &serde_hjson::Value, tag: impl Into<Tag>) -
serde_hjson::Value::String(s) => {
Value::Primitive(Primitive::String(String::from(s))).tagged(tag)
}
serde_hjson::Value::Array(a) => Value::List(
serde_hjson::Value::Array(a) => Value::Table(
a.iter()
.map(|x| convert_json_value_to_nu_value(x, tag))
.collect(),
@ -126,7 +125,7 @@ fn from_json(
match from_json_string_to_value(concat_string, name_span) {
Ok(x) =>
match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::errors::ShellError;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use rusqlite::{types::ValueRef, Connection, Row, NO_PARAMS};
use std::io::Write;
@ -76,11 +76,11 @@ pub fn convert_sqlite_file_to_nu_value(
"table_name".to_string(),
Value::Primitive(Primitive::String(table_name)).tagged(tag.clone()),
);
meta_dict.insert_tagged("table_values", Value::List(out).tagged(tag.clone()));
meta_dict.insert_tagged("table_values", Value::Table(out).tagged(tag.clone()));
meta_out.push(meta_dict.into_tagged_value());
}
let tag = tag.into();
Ok(Value::List(meta_out).tagged(tag))
Ok(Value::Table(meta_out).tagged(tag))
}
fn convert_sqlite_row_to_nu_value(
@ -140,7 +140,7 @@ fn from_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputSt
Value::Binary(vb) =>
match from_sqlite_bytes_to_value(vb, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromTOML;
@ -34,7 +34,7 @@ pub fn convert_toml_value_to_nu_value(v: &toml::Value, tag: impl Into<Tag>) -> T
toml::Value::Integer(n) => Value::number(n).tagged(tag),
toml::Value::Float(n) => Value::number(n).tagged(tag),
toml::Value::String(s) => Value::Primitive(Primitive::String(String::from(s))).tagged(tag),
toml::Value::Array(a) => Value::List(
toml::Value::Array(a) => Value::Table(
a.iter()
.map(|x| convert_toml_value_to_nu_value(x, tag))
.collect(),
@ -98,7 +98,7 @@ pub fn from_toml(
match from_toml_string_to_value(concat_string, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use csv::ReaderBuilder;
@ -78,7 +78,7 @@ pub fn from_tsv_string_to_value(
}
}
Ok(Tagged::from_item(Value::List(rows), tag))
Ok(Tagged::from_item(Value::Table(rows), tag))
}
fn from_tsv(
@ -116,7 +116,7 @@ fn from_tsv(
match from_tsv_string_to_value(concat_string, skip_headers, name_span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromXML;
@ -55,7 +55,7 @@ fn from_node_to_value<'a, 'd>(n: &roxmltree::Node<'a, 'd>, tag: impl Into<Tag>)
.collect();
let mut collected = TaggedDictBuilder::new(tag);
collected.insert(name.clone(), Value::List(children_values));
collected.insert(name.clone(), Value::Table(children_values));
collected.into_tagged_value()
} else if n.is_comment() {
@ -113,7 +113,7 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
match from_xml_string_to_value(concat_string, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromYAML;
@ -62,7 +62,7 @@ fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, tag: impl Into<Tag>) ->
Value::Primitive(Primitive::from(n.as_f64().unwrap())).tagged(tag)
}
serde_yaml::Value::String(s) => Value::string(s).tagged(tag),
serde_yaml::Value::Sequence(a) => Value::List(
serde_yaml::Value::Sequence(a) => Value::Table(
a.iter()
.map(|x| convert_yaml_value_to_nu_value(x, tag))
.collect(),
@ -127,7 +127,7 @@ fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
match from_yaml_string_to_value(concat_string, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::prelude::*;
pub struct Get;
@ -73,7 +73,7 @@ pub fn get(
for field in &fields {
match get_member(field, &item) {
Ok(Tagged {
item: Value::List(l),
item: Value::Table(l),
..
}) => {
for item in l {

View File

@ -1,7 +1,7 @@
use crate::commands::command::CommandAction;
use crate::commands::PerItemCommand;
use crate::errors::ShellError;
use crate::object::{command_dict, TaggedDictBuilder};
use crate::data::{command_dict, TaggedDictBuilder};
use crate::parser::registry;
use crate::prelude::*;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
use log::trace;

View File

@ -266,7 +266,7 @@ macro_rules! command {
Extract {
$($extract:tt)* {
use $crate::object::types::ExtractType;
use $crate::data::types::ExtractType;
let value = $args.expect_nth($($positional_count)*)?;
Block::extract(value)?
}
@ -321,7 +321,7 @@ macro_rules! command {
Extract {
$($extract:tt)* {
use $crate::object::types::ExtractType;
use $crate::data::types::ExtractType;
let value = $args.expect_nth($($positional_count)*)?;
<$param_kind>::extract(&value)?
}

View File

@ -1,7 +1,7 @@
use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::data::Value;
use crate::errors::ShellError;
use crate::object::Value;
use crate::parser::hir::SyntaxType;
use crate::parser::registry::Signature;
use crate::prelude::*;
@ -107,7 +107,7 @@ fn run(
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec {
match res {
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
for l in list {
yield Ok(ReturnSuccess::Value(l));
}

View File

@ -1,7 +1,7 @@
use crate::commands::WholeStreamCommand;
use crate::context::CommandRegistry;
use crate::errors::ShellError;
use crate::object::base::select_fields;
use crate::data::base::select_fields;
use crate::prelude::*;
#[derive(Deserialize)]

View File

@ -1,7 +1,7 @@
use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::parser::hir::SyntaxType;
use crate::parser::registry::Signature;
use crate::prelude::*;
@ -116,7 +116,7 @@ fn run(
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec {
match res {
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
for l in list {
yield Ok(ReturnSuccess::Value(l));
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::TaggedDictBuilder;
use crate::data::TaggedDictBuilder;
use crate::prelude::*;
use std::time::Duration;
use std::usize;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::base::reject_fields;
use crate::data::base::reject_fields;
use crate::prelude::*;
#[derive(Deserialize)]

View File

@ -1,6 +1,6 @@
use crate::commands::{UnevaluatedCallInfo, WholeStreamCommand};
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::prelude::*;
use std::path::{Path, PathBuf};

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::TaggedDictBuilder;
use crate::data::TaggedDictBuilder;
use crate::prelude::*;
pub struct Shells;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{TaggedDictBuilder, Value};
use crate::data::{TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct Size;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use log::trace;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
use log::trace;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{TaggedDictBuilder, Value};
use crate::data::{TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct Tags;

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Dictionary, Primitive, Value};
use crate::data::{Dictionary, Primitive, Value};
use crate::prelude::*;
use bson::{encode_document, oid::ObjectId, spec::BinarySubtype, Bson, Document};
use std::convert::TryInto;
@ -51,14 +51,14 @@ pub fn value_to_bson_value(v: &Tagged<Value>) -> Result<Bson, ShellError> {
Value::Primitive(Primitive::Nothing) => Bson::Null,
Value::Primitive(Primitive::String(s)) => Bson::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => Bson::String(s.display().to_string()),
Value::List(l) => Bson::Array(
Value::Table(l) => Bson::Array(
l.iter()
.map(|x| value_to_bson_value(x))
.collect::<Result<_, _>>()?,
),
Value::Block(_) => Bson::Null,
Value::Binary(b) => Bson::Binary(BinarySubtype::Generic, b.clone()),
Value::Object(o) => object_value_to_bson(o)?,
Value::Row(o) => object_value_to_bson(o)?,
})
}
@ -241,7 +241,7 @@ fn to_bson(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
use csv::WriterBuilder;
@ -39,8 +39,8 @@ pub fn value_to_csv_value(v: &Value) -> Value {
Value::Primitive(Primitive::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())),
Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(b.clone())),
Value::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())),
Value::Object(o) => Value::Object(o.clone()),
Value::List(l) => Value::List(l.clone()),
Value::Row(o) => Value::Row(o.clone()),
Value::Table(l) => Value::Table(l.clone()),
Value::Block(_) => Value::Primitive(Primitive::Nothing),
_ => Value::Primitive(Primitive::Nothing),
}
@ -51,8 +51,8 @@ fn to_string_helper(v: &Value) -> Result<String, ShellError> {
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
Value::List(_) => return Ok(String::from("[list list]")),
Value::Object(_) => return Ok(String::from("[object]")),
Value::Table(_) => return Ok(String::from("[list list]")),
Value::Row(_) => return Ok(String::from("[object]")),
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
_ => return Err(ShellError::string("Unexpected value")),
}
@ -72,7 +72,7 @@ fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
pub fn to_string(v: &Value) -> Result<String, ShellError> {
match v {
Value::Object(o) => {
Value::Row(o) => {
let mut wtr = WriterBuilder::new().from_writer(vec![]);
let mut fields: VecDeque<String> = VecDeque::new();
let mut values: VecDeque<String> = VecDeque::new();
@ -92,7 +92,7 @@ pub fn to_string(v: &Value) -> Result<String, ShellError> {
)
.map_err(|_| ShellError::string("Could not convert record"))?);
}
Value::List(list) => {
Value::Table(list) => {
let mut wtr = WriterBuilder::new().from_writer(vec![]);
let merged_descriptors = merge_descriptors(&list);
@ -134,7 +134,7 @@ fn to_csv(
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
pub struct ToJSON;
@ -48,7 +48,7 @@ pub fn value_to_json_value(v: &Tagged<Value>) -> Result<serde_json::Value, Shell
Value::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => serde_json::Value::String(s.display().to_string()),
Value::List(l) => serde_json::Value::Array(json_list(l)?),
Value::Table(l) => serde_json::Value::Array(json_list(l)?),
Value::Block(_) => serde_json::Value::Null,
Value::Binary(b) => serde_json::Value::Array(
b.iter()
@ -57,7 +57,7 @@ pub fn value_to_json_value(v: &Tagged<Value>) -> Result<serde_json::Value, Shell
})
.collect(),
),
Value::Object(o) => {
Value::Row(o) => {
let mut m = serde_json::Map::new();
for (k, v) in o.entries.iter() {
m.insert(k.clone(), value_to_json_value(v)?);
@ -85,7 +85,7 @@ fn to_json(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Dictionary, Primitive, Value};
use crate::data::{Dictionary, Primitive, Value};
use crate::prelude::*;
use hex::encode;
use rusqlite::{Connection, NO_PARAMS};
@ -71,7 +71,7 @@ fn comma_concat(acc: String, current: String) -> String {
fn get_columns(rows: &Vec<Tagged<Value>>) -> Result<String, std::io::Error> {
match &rows[0].item {
Value::Object(d) => Ok(d
Value::Row(d) => Ok(d
.entries
.iter()
.map(|(k, _v)| k.clone())
@ -107,7 +107,7 @@ fn get_insert_values(rows: Vec<Tagged<Value>>) -> Result<String, std::io::Error>
let values: Result<Vec<_>, _> = rows
.into_iter()
.map(|value| match value.item {
Value::Object(d) => Ok(format!(
Value::Row(d) => Ok(format!(
"({})",
d.entries
.iter()
@ -139,7 +139,7 @@ fn generate_statements(table: Dictionary) -> Result<(String, String), std::io::E
};
let (columns, insert_values) = match table.entries.get("table_values") {
Some(Tagged {
item: Value::List(l),
item: Value::Table(l),
..
}) => (get_columns(l), get_insert_values(l.to_vec())),
_ => {
@ -169,7 +169,7 @@ fn sqlite_input_stream_to_bytes(
let tag = values[0].tag.clone();
for value in values.into_iter() {
match value.item() {
Value::Object(d) => {
Value::Row(d) => {
let (create, insert) = generate_statements(d.to_owned())?;
match conn
.execute(&create, NO_PARAMS)

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
pub struct ToTOML;
@ -47,12 +47,12 @@ pub fn value_to_toml_value(v: &Tagged<Value>) -> Result<toml::Value, ShellError>
Value::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => toml::Value::String(s.display().to_string()),
Value::List(l) => toml::Value::Array(collect_values(l)?),
Value::Table(l) => toml::Value::Array(collect_values(l)?),
Value::Block(_) => toml::Value::String("<Block>".to_string()),
Value::Binary(b) => {
toml::Value::Array(b.iter().map(|x| toml::Value::Integer(*x as i64)).collect())
}
Value::Object(o) => {
Value::Row(o) => {
let mut m = toml::map::Map::new();
for (k, v) in o.entries.iter() {
m.insert(k.clone(), value_to_toml_value(v)?);
@ -80,7 +80,7 @@ fn to_toml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
use csv::WriterBuilder;
@ -39,8 +39,8 @@ pub fn value_to_tsv_value(v: &Value) -> Value {
Value::Primitive(Primitive::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())),
Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(b.clone())),
Value::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())),
Value::Object(o) => Value::Object(o.clone()),
Value::List(l) => Value::List(l.clone()),
Value::Row(o) => Value::Row(o.clone()),
Value::Table(l) => Value::Table(l.clone()),
Value::Block(_) => Value::Primitive(Primitive::Nothing),
_ => Value::Primitive(Primitive::Nothing),
}
@ -51,8 +51,8 @@ fn to_string_helper(v: &Value) -> Result<String, ShellError> {
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
Value::List(_) => return Ok(String::from("[table]")),
Value::Object(_) => return Ok(String::from("[row]")),
Value::Table(_) => return Ok(String::from("[table]")),
Value::Row(_) => return Ok(String::from("[row]")),
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
_ => Err(ShellError::string("Unexpected value")),
}
@ -72,7 +72,7 @@ fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
pub fn to_string(v: &Value) -> Result<String, ShellError> {
match v {
Value::Object(o) => {
Value::Row(o) => {
let mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]);
let mut fields: VecDeque<String> = VecDeque::new();
let mut values: VecDeque<String> = VecDeque::new();
@ -91,7 +91,7 @@ pub fn to_string(v: &Value) -> Result<String, ShellError> {
)
.map_err(|_| ShellError::string("Could not convert record"))?);
}
Value::List(list) => {
Value::Table(list) => {
let mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]);
let merged_descriptors = merge_descriptors(&list);
@ -133,7 +133,7 @@ fn to_tsv(
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
pub struct ToYAML;
@ -45,7 +45,7 @@ pub fn value_to_yaml_value(v: &Tagged<Value>) -> Result<serde_yaml::Value, Shell
Value::Primitive(Primitive::String(s)) => serde_yaml::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => serde_yaml::Value::String(s.display().to_string()),
Value::List(l) => {
Value::Table(l) => {
let mut out = vec![];
for value in l {
@ -60,7 +60,7 @@ pub fn value_to_yaml_value(v: &Tagged<Value>) -> Result<serde_yaml::Value, Shell
.map(|x| serde_yaml::Value::Number(serde_yaml::Number::from(*x)))
.collect(),
),
Value::Object(o) => {
Value::Row(o) => {
let mut m = serde_yaml::Mapping::new();
for (k, v) in o.entries.iter() {
m.insert(
@ -81,7 +81,7 @@ fn to_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::prelude::*;
pub struct Trim;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{Dictionary, Value};
use crate::data::{Dictionary, Value};
use crate::parser::registry::Signature;
use crate::prelude::*;
use indexmap::IndexMap;
@ -39,6 +39,6 @@ pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
Tagged::from_simple_spanned_item(Value::string(clap::crate_version!()), span),
);
let value = Tagged::from_simple_spanned_item(Value::Object(Dictionary::from(indexmap)), span);
let value = Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span);
Ok(OutputStream::one(value))
}

View File

@ -1,5 +1,5 @@
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::prelude::*;
use crate::commands::WholeStreamCommand;