Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uwdata/mosaic-sql

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uwdata/mosaic-sql - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

src/load/load.js

83

dist/mosaic-sql.js

@@ -652,3 +652,3 @@ // src/ref.js

if (typeof value === "number") {
spec = value > 0 && value < 1 ? { perc: 100 * value, method } : { rows: Math.round(value, method) };
spec = value > 0 && value < 1 ? { perc: 100 * value, method } : { rows: Math.round(value), method };
}

@@ -685,2 +685,6 @@ query.sample = spec;

}
$groupby(...expr) {
this.query.groupby = [];
return this.groupby(...expr);
}
having(...expr) {

@@ -914,41 +918,10 @@ const { query } = this;

// src/load/create.js
function create(name, query, options = {}) {
const { temp, replace, type = "TABLE" } = options;
const create2 = `CREATE${replace ? " OR REPLACE" : ""}`;
const spec = `${temp ? "TEMP " : ""}${type}${replace ? "" : " IF NOT EXISTS"}`;
return `${create2} ${spec} ${name} AS ${query}`;
function create(name, query, {
replace = false,
temp = true,
view = false
} = {}) {
return "CREATE" + (replace ? " OR REPLACE " : " ") + (temp ? "TEMP " : "") + (view ? "VIEW" : "TABLE") + (replace ? " " : " IF NOT EXISTS ") + name + " AS " + query;
}
// src/load/parameters.js
function parameters(options) {
return Object.entries(options).map(([key, value]) => {
const t = typeof value;
const v = t === "boolean" ? String(value) : t === "string" ? `'${value}'` : value;
return `${key}=${v}`;
}).join(", ");
}
// src/load/csv.js
function loadCSV(tableName, fileName, options = {}) {
const { select = ["*"], temp, replace, ...csvOptions } = options;
const params = parameters({ auto_detect: true, sample_size: -1, ...csvOptions });
const query = `SELECT ${select.join(", ")} FROM read_csv('${fileName}', ${params})`;
return create(tableName, query, { temp, replace });
}
// src/load/json.js
function loadJSON(tableName, fileName, options = {}) {
const { select = ["*"], temp, replace, ...jsonOptions } = options;
const params = parameters({ auto_detect: true, json_format: "auto", ...jsonOptions });
const query = `SELECT ${select.join(", ")} FROM read_json('${fileName}', ${params})`;
return create(tableName, query, { temp, replace });
}
// src/load/parquet.js
function loadParquet(tableName, fileName, options = {}) {
const { select = ["*"], ...tableOptions } = options;
const query = `SELECT ${select.join(", ")} FROM read_parquet('${fileName}')`;
return create(tableName, query, tableOptions);
}
// src/load/sql-from.js

@@ -975,2 +948,34 @@ function sqlFrom(data, {

}
// src/load/load.js
function load(method, tableName, fileName, options = {}, defaults = {}) {
const { select = ["*"], where, view, temp, replace, ...file } = options;
const params = parameters({ ...defaults, ...file });
const read = `${method}('${fileName}'${params ? ", " + params : ""})`;
const filter = where ? ` WHERE ${where}` : "";
const query = `SELECT ${select.join(", ")} FROM ${read}${filter}`;
return create(tableName, query, { view, temp, replace });
}
function loadCSV(tableName, fileName, options) {
return load("read_csv", tableName, fileName, options, { auto_detect: true, sample_size: -1 });
}
function loadJSON(tableName, fileName, options) {
return load("read_json", tableName, fileName, options, { auto_detect: true, json_format: "auto" });
}
function loadParquet(tableName, fileName, options) {
return load("read_parquet", tableName, fileName, options);
}
function loadObjects(tableName, data, options = {}) {
const { select = ["*"], ...opt } = options;
const values = sqlFrom(data);
const query = select.length === 1 && select[0] === "*" ? values : `SELECT ${select} FROM ${values}`;
return create(tableName, query, opt);
}
function parameters(options) {
return Object.entries(options).map(([key, value]) => {
const t = typeof value;
const v = t === "boolean" ? String(value) : t === "string" ? `'${value}'` : value;
return `${key}=${v}`;
}).join(", ");
}
export {

@@ -1032,2 +1037,3 @@ Query,

loadJSON,
loadObjects,
loadParquet,

@@ -1067,3 +1073,2 @@ lower,

sql,
sqlFrom,
stddev,

@@ -1070,0 +1075,0 @@ stddevPop,

@@ -1,1 +0,1 @@

var y=class{constructor(t,e){t&&(this.table=String(t)),e&&(this.column=e)}get columns(){return this.column?[this.column]:[]}toString(){let{table:t,column:e}=this;if(e){let n=e.startsWith("*")?e:`"${e}"`;return`${t?`"${t}".`:""}${n}`}else return t?`"${t}"`:"NULL"}};function X(r,t){return r instanceof y&&r.column===t}function l(r){return typeof r=="string"?W(r):r}function D(r){return typeof r=="string"?V(r):r}function V(r){return new y(r)}function W(r,t){return arguments.length===1&&(t=r,r=null),new y(r,t)}function tt(r){return new y(r,"*")}function et(r){return typeof r=="string"?`"${r}"`:d(r)}function d(r){switch(typeof r){case"boolean":return r?"TRUE":"FALSE";case"string":return`'${r}'`;case"number":return Number.isFinite(r)?String(r):"NULL";default:if(r==null)return"NULL";if(r instanceof Date){let t=+r;if(Number.isNaN(t))return"NULL";let e=r.getUTCFullYear(),n=r.getUTCMonth(),o=r.getUTCDate();return t===Date.UTC(e,n,o)?`MAKE_DATE(${e}, ${n+1}, ${o})`:`EPOCH_MS(${t})`}else return r instanceof RegExp?`'${r.source}'`:String(r)}}var b=r=>typeof r?.addEventListener=="function";function M(r){return r instanceof A}var A=class{constructor(t,e,n){this._expr=Array.isArray(t)?t:[t],this._deps=e||[],this.annotate(n);let o=this._expr.filter(s=>b(s));o.length>0?(this._params=Array.from(new Set(o)),this._params.forEach(s=>{s.addEventListener("value",()=>rt(this,this.map?.get("value")))})):this.addEventListener=void 0}get value(){return this}get columns(){let{_params:t,_deps:e}=this;if(t){let n=new Set(t.flatMap(o=>{let s=o.value?.columns;return Array.isArray(s)?s:[]}));if(n.size){let o=new Set(e);return n.forEach(s=>o.add(s)),Array.from(o)}}return e}get column(){return this._deps.length?this._deps[0]:this.columns[0]}annotate(...t){return Object.assign(this,...t)}toString(){return this._expr.map(t=>b(t)&&!M(t)?d(t.value):t).join("")}addEventListener(t,e){let n=this.map||(this.map=new Map);(n.get(t)||(n.set(t,new Set),n.get(t))).add(e)}};function rt(r,t){if(t?.size)return Promise.allSettled(Array.from(t,e=>e(r)))}function Y(r,t){let e=[r[0]],n=new Set,o=t.length;for(let s=0,i=0;s<o;){let c=t[s];b(c)?e[++i]=c:(Array.isArray(c?.columns)&&c.columns.forEach(x=>n.add(x)),e[i]+=typeof c=="string"?c:d(c));let p=r[++s];b(e[i])?e[++i]=p:e[i]+=p}return{spans:e,cols:Array.from(n)}}function u(r,...t){let{spans:e,cols:n}=Y(r,t);return new A(e,n)}function nt(r){let t=l(r);return u`${t} DESC NULLS LAST`.annotate({label:t?.label,desc:!0})}var ot=r=>({value:r,toString:()=>d(r)});function C(r){r(this.op,this),this.children?.forEach(t=>t.visit(r))}function Q(r,t){let e=t.filter(o=>o!=null).map(l),n=e.map((o,s)=>s?` ${r} `:"");return t.length&&n.push(""),u(n,...e).annotate({op:r,children:e,visit:C})}var st=(...r)=>Q("AND",r.flat()),it=(...r)=>Q("OR",r.flat()),ct=r=>t=>u`(${r} ${l(t)})`.annotate({op:r,a:t,visit:C}),at=ct("NOT"),k=r=>t=>u`(${l(t)} ${r})`.annotate({op:r,a:t,visit:C}),ut=k("IS NULL"),lt=k("IS NOT NULL"),T=r=>(t,e)=>u`(${l(t)} ${r} ${l(e)})`.annotate({op:r,a:t,b:e,visit:C}),pt=T("="),ft=T("<>"),mt=T("<"),ht=T(">"),gt=T("<="),xt=T(">="),Et=T("IS DISTINCT FROM"),dt=T("IS NOT DISTINCT FROM");function v(r,t,e,n){t=l(t);let o=r.startsWith("NOT ")?"NOT ":"";return(e?n?u`${o}(${e[0]} <= ${t} AND ${t} < ${e[1]})`:u`(${t} ${r} ${e[0]} AND ${e[1]})`:u``).annotate({op:r,visit:C,field:t,range:e})}var $t=(r,t,e)=>v("BETWEEN",r,t,e),Nt=(r,t,e)=>v("NOT BETWEEN",r,t,e);function q(r,t){return Array.from({length:r},()=>t)}function g(r,t){return(...e)=>{let n=e.map(l),o=t?`::${t}`:"";return(n.length?u([`${r}(`,...q(n.length-1,", "),`)${o}`],...n):u`${r}()${o}`).annotate({func:r,args:n})}}var yt=g("REGEXP_MATCHES"),St=g("CONTAINS"),wt=g("PREFIX"),Rt=g("SUFFIX"),At=g("LOWER"),Tt=g("UPPER"),bt=g("LENGTH"),qt=g("ISNAN"),Lt=g("ISFINITE"),Ot=g("ISINF");var $=class extends A{constructor(t,e,n,o,s="",i="",c=""){let p;if(o&&!(s||i||c))p=o?u`${e} OVER "${o}"`:u`${e} OVER ()`;else{let P=s&&i?" ":"",U=(s||i)&&c?" ":"";p=u`${e} OVER (${o?`"${o}" `:""}${s}${P}${i}${U}${c})`}n&&(p=u`(${p})::${n}`);let{_expr:R,_deps:_}=p;super(R,_,{window:t,func:e,type:n,name:o,group:s,order:i,frame:c})}get basis(){return this.column}get label(){let{func:t}=this;return t.label??t.toString()}over(t){let{window:e,func:n,type:o,group:s,order:i,frame:c}=this;return new $(e,n,o,t,s,i,c)}partitionby(...t){let e=t.flat().filter(R=>R).map(l),n=u(["PARTITION BY ",q(e.length-1,", "),""],...e),{window:o,func:s,type:i,name:c,order:p,frame:x}=this;return new $(o,s,i,c,n,p,x)}orderby(...t){let e=t.flat().filter(R=>R).map(l),n=u(["ORDER BY ",q(e.length-1,", "),""],...e),{window:o,func:s,type:i,name:c,group:p,frame:x}=this;return new $(o,s,i,c,p,n,x)}rows(t){let e=H("ROWS",t),{window:n,func:o,type:s,name:i,group:c,order:p}=this;return new $(n,o,s,i,c,p,e)}range(t){let e=H("RANGE",t),{window:n,func:o,type:s,name:i,group:c,order:p}=this;return new $(n,o,s,i,c,p,e)}};function H(r,t){if(b(t)){let e=u`${t}`;return e.toString=()=>`${r} ${K(t.value)}`,e}return`${r} ${K(t)}`}function K(r){let[t,e]=r,n=t===0?"CURRENT ROW":Number.isFinite(t)?`${Math.abs(t)} PRECEDING`:"UNBOUNDED PRECEDING",o=e===0?"CURRENT ROW":Number.isFinite(e)?`${Math.abs(e)} FOLLOWING`:"UNBOUNDED FOLLOWING";return`BETWEEN ${n} AND ${o}`}function N(r,t){return(...e)=>{let n=g(r)(...e);return new $(r,n,t)}}var It=N("ROW_NUMBER","INTEGER"),Dt=N("RANK","INTEGER"),Ct=N("DENSE_RANK","INTEGER"),_t=N("PERCENT_RANK"),Pt=N("CUME_DIST"),Ut=N("NTILE"),Mt=N("LAG"),Ft=N("LEAD"),Gt=N("FIRST_VALUE"),jt=N("LAST_VALUE"),Yt=N("NTH_VALUE");function Bt(r,...t){return u(r,...t).annotate({aggregate:!0})}var L=class extends A{constructor(t,e,n,o,s){e=(e||[]).map(l);let{strings:i,exprs:c}=Xt(t,e,n,o,s),{spans:p,cols:x}=Y(i,c);super(p,x,{aggregate:t,args:e,type:n,isDistinct:o,filter:s})}get basis(){return this.column}get label(){let{aggregate:t,args:e,isDistinct:n}=this,o=n?"DISTINCT"+(e.length?" ":""):"",s=e.length?`(${o}${e.map(Vt).join(", ")})`:"";return`${t.toLowerCase()}${s}`}distinct(){let{aggregate:t,args:e,type:n,filter:o}=this;return new L(t,e,n,!0,o)}where(t){let{aggregate:e,args:n,type:o,isDistinct:s}=this;return new L(e,n,o,s,t)}window(){let{aggregate:t,args:e,type:n,isDistinct:o}=this,s=new L(t,e,null,o);return new $(t,s,n)}partitionby(...t){return this.window().partitionby(...t)}orderby(...t){return this.window().orderby(...t)}rows(t,e){return this.window().rows(t,e)}range(t,e){return this.window().range(t,e)}};function Xt(r,t,e,n,o){let s=`)${e?`::${e}`:""}`,i=[`${r}(${n?"DISTINCT ":""}`],c=[];return t.length?(i=i.concat([...q(t.length-1,", "),`${s}${o?" FILTER (WHERE ":""}`,...o?[")"]:[]]),c=[...t,...o?[o]:[]]):i[0]+="*"+s,{exprs:c,strings:i}}function Vt(r){let t=d(r);return t&&t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function a(r,t){return(...e)=>new L(r,e,t)}var Wt=a("COUNT","INTEGER"),Qt=a("AVG"),kt=a("AVG"),vt=a("MAD"),Ht=a("MAX"),Kt=a("MIN"),zt=a("SUM","DOUBLE"),Jt=a("PRODUCT"),Zt=a("MEDIAN"),te=a("QUANTILE"),ee=a("MODE"),re=a("VARIANCE"),ne=a("STDDEV"),oe=a("SKEWNESS"),se=a("KURTOSIS"),ie=a("ENTROPY"),ce=a("VAR_POP"),ae=a("STDDEV_POP"),ue=a("CORR"),le=a("COVAR_POP"),pe=a("REGR_INTERCEPT"),fe=a("REGR_SLOPE"),me=a("REGR_COUNT"),he=a("REGR_R2"),ge=a("REGR_SYY"),xe=a("REGR_SXX"),Ee=a("REGR_SXY"),de=a("REGR_AVGX"),$e=a("REGR_AVGY"),Ne=a("FIRST"),ye=a("LAST"),Se=a("ARG_MIN"),we=a("ARG_MAX"),Re=a("STRING_AGG"),Ae=a("ARRAY_AGG");function B(r,t){let e=l(r),n=u`CAST(${e} AS ${t})`;return Object.defineProperty(n,"label",{enumerable:!0,get(){return r.label}}),Object.defineProperty(n,"aggregate",{enumerable:!0,get(){return r.aggregate||!1}}),n}var Te=r=>B(r,"DOUBLE"),be=r=>B(r,"INTEGER");var qe=r=>{let t=l(r);return u`(1000 * (epoch(${t}) - second(${t})) + millisecond(${t}))::DOUBLE`},Le=r=>{let t=l(r);return u`MAKE_DATE(2012, MONTH(${t}), 1)`.annotate({label:"month"})},Oe=r=>{let t=l(r);return u`MAKE_DATE(2012, MONTH(${t}), DAY(${t}))`.annotate({label:"date"})},Ie=r=>{let t=l(r);return u`MAKE_DATE(2012, 1, DAY(${t}))`.annotate({label:"date"})};var S=class{static select(...t){return new S().select(...t)}static from(...t){return new S().from(...t)}static with(...t){return new S().with(...t)}static union(...t){return new w("UNION",t.flat())}static unionAll(...t){return new w("UNION ALL",t.flat())}static intersect(...t){return new w("INTERSECT",t.flat())}static except(...t){return new w("EXCEPT",t.flat())}constructor(){this.query={with:[],select:[],from:[],where:[],groupby:[],having:[],window:[],qualify:[],orderby:[]}}clone(){let t=new S;return t.query={...this.query},t}with(...t){let{query:e}=this;if(t.length===0)return e.with;{let n=[],o=(s,i)=>{let c=i.clone();c.cteFor=this,n.push({as:s,query:c})};return t.flat().forEach(s=>{if(s!=null)if(s.as&&s.query)o(s.as,s.query);else for(let i in s)o(i,s[i])}),e.with=e.with.concat(n),this}}select(...t){let{query:e}=this;if(t.length===0)return e.select;{let n=[];for(let o of t.flat())if(o!=null)if(typeof o=="string")n.push({as:o,expr:l(o)});else if(o instanceof y)n.push({as:o.column,expr:o});else if(Array.isArray(o))n.push({as:o[0],expr:o[1]});else for(let s in o)n.push({as:F(s),expr:l(o[s])});return e.select=e.select.concat(n),this}}$select(...t){return this.query.select=[],this.select(...t)}distinct(t=!0){return this.query.distinct=!!t,this}from(...t){let{query:e}=this;if(t.length===0)return e.from;{let n=[];return t.flat().forEach(o=>{if(o!=null)if(typeof o=="string")n.push({as:o,from:D(o)});else if(o instanceof y)n.push({as:o.table,from:o});else if(G(o)||M(o))n.push({from:o});else if(Array.isArray(o))n.push({as:F(o[0]),from:D(o[1])});else for(let s in o)n.push({as:F(s),from:D(o[s])})}),e.from=e.from.concat(n),this}}$from(...t){return this.query.from=[],this.from(...t)}sample(t,e){let{query:n}=this;if(arguments.length===0)return n.sample;{let o=t;return typeof t=="number"&&(o=t>0&&t<1?{perc:100*t,method:e}:{rows:Math.round(t,e)}),n.sample=o,this}}where(...t){let{query:e}=this;return t.length===0?e.where:(e.where=e.where.concat(t.flat().filter(n=>n)),this)}$where(...t){return this.query.where=[],this.where(...t)}groupby(...t){let{query:e}=this;return t.length===0?e.groupby:(e.groupby=e.groupby.concat(t.flat().filter(n=>n).map(l)),this)}having(...t){let{query:e}=this;return t.length===0?e.having:(e.having=e.having.concat(t.flat().filter(n=>n)),this)}window(...t){let{query:e}=this;if(t.length===0)return e.window;{let n=[];return t.flat().forEach(o=>{if(o!=null)for(let s in o)n.push({as:F(s),expr:o[s]})}),e.window=e.window.concat(n),this}}qualify(...t){let{query:e}=this;return t.length===0?e.qualify:(e.qualify=e.qualify.concat(t.flat().filter(n=>n)),this)}orderby(...t){let{query:e}=this;return t.length===0?e.orderby:(e.orderby=e.orderby.concat(t.flat().filter(n=>n).map(l)),this)}limit(t){let{query:e}=this;return arguments.length===0?e.limit:(e.limit=Number.isFinite(t)?t:void 0,this)}offset(t){let{query:e}=this;return arguments.length===0?e.offset:(e.offset=Number.isFinite(t)?t:void 0,this)}get subqueries(){let{query:t,cteFor:e}=this,o=(e?.query||t).with?.reduce((i,{as:c,query:p})=>(i[c]=p,i),{}),s=[];return t.from.forEach(({from:i})=>{if(G(i))s.push(i);else if(o[i.table]){let c=o[i.table];s.push(c)}}),s}toString(){let{select:t,distinct:e,from:n,sample:o,where:s,groupby:i,having:c,window:p,qualify:x,orderby:R,limit:_,offset:P,with:U}=this.query,h=[];if(U.length){let f=U.map(({as:m,query:E})=>`"${m}" AS (${E})`);h.push(`WITH ${f.join(", ")}`)}let z=t.map(({as:f,expr:m})=>X(m,f)&&!m.table?`${m}`:`${m} AS "${f}"`);if(h.push(`SELECT${e?" DISTINCT":""} ${z.join(", ")}`),n.length){let f=n.map(({as:m,from:E})=>{let I=G(E)?`(${E})`:`${E}`;return!m||m===E.table?I:`${I} AS "${m}"`});h.push(`FROM ${f.join(", ")}`)}if(s.length){let f=s.map(String).filter(m=>m).join(" AND ");f&&h.push(`WHERE ${f}`)}if(o){let{rows:f,perc:m,method:E,seed:I}=o,J=f?`${f} ROWS`:`${m} PERCENT`,Z=E?` (${E}${I!=null?`, ${I}`:""})`:"";h.push(`USING SAMPLE ${J}${Z}`)}if(i.length&&h.push(`GROUP BY ${i.join(", ")}`),c.length){let f=c.map(String).filter(m=>m).join(" AND ");f&&h.push(`HAVING ${f}`)}if(p.length){let f=p.map(({as:m,expr:E})=>`"${m}" AS (${E})`);h.push(`WINDOW ${f.join(", ")}`)}if(x.length){let f=x.map(String).filter(m=>m).join(" AND ");f&&h.push(`QUALIFY ${f}`)}return R.length&&h.push(`ORDER BY ${R.join(", ")}`),Number.isFinite(_)&&h.push(`LIMIT ${_}`),Number.isFinite(P)&&h.push(`OFFSET ${P}`),h.join(" ")}},w=class{constructor(t,e){this.op=t,this.queries=e.map(n=>n.clone()),this.query={orderby:[]}}clone(){let t=new w(this.op,this.queries);return t.query={...this.query},t}orderby(...t){let{query:e}=this;return t.length===0?e.orderby:(e.orderby=e.orderby.concat(t.flat().filter(n=>n).map(l)),this)}limit(t){let{query:e}=this;return arguments.length===0?e.limit:(e.limit=Number.isFinite(t)?t:void 0,this)}offset(t){let{query:e}=this;return arguments.length===0?e.offset:(e.offset=Number.isFinite(t)?t:void 0,this)}get subqueries(){let{queries:t,cteFor:e}=this;return e&&t.forEach(n=>n.cteFor=e),t}toString(){let{op:t,queries:e,query:{orderby:n,limit:o,offset:s}}=this,i=[e.join(` ${t} `)];return n.length&&i.push(`ORDER BY ${n.join(", ")}`),Number.isFinite(o)&&i.push(`LIMIT ${o}`),Number.isFinite(s)&&i.push(`OFFSET ${s}`),i.join(" ")}};function G(r){return r instanceof S||r instanceof w}function F(r){return De(r)?r.slice(1,-1):r}function De(r){return r[0]==='"'&&r[r.length-1]==='"'}function O(r,t,e={}){let{temp:n,replace:o,type:s="TABLE"}=e,i=`CREATE${o?" OR REPLACE":""}`,c=`${n?"TEMP ":""}${s}${o?"":" IF NOT EXISTS"}`;return`${i} ${c} ${r} AS ${t}`}function j(r){return Object.entries(r).map(([t,e])=>{let n=typeof e,o=n==="boolean"?String(e):n==="string"?`'${e}'`:e;return`${t}=${o}`}).join(", ")}function Ce(r,t,e={}){let{select:n=["*"],temp:o,replace:s,...i}=e,c=j({auto_detect:!0,sample_size:-1,...i}),p=`SELECT ${n.join(", ")} FROM read_csv('${t}', ${c})`;return O(r,p,{temp:o,replace:s})}function _e(r,t,e={}){let{select:n=["*"],temp:o,replace:s,...i}=e,c=j({auto_detect:!0,json_format:"auto",...i}),p=`SELECT ${n.join(", ")} FROM read_json('${t}', ${c})`;return O(r,p,{temp:o,replace:s})}function Pe(r,t,e={}){let{select:n=["*"],...o}=e,s=`SELECT ${n.join(", ")} FROM read_parquet('${t}')`;return O(r,s,o)}function Ue(r,{columns:t=Object.keys(r?.[0]||{})}={}){let e=[];if(Array.isArray(t)?(e=t,t=e.reduce((o,s)=>(o[s]=s,o),{})):t&&(e=Object.keys(t)),!e.length)throw new Error("Can not create table from empty column set.");let n=[];for(let o of r){let s=e.map(i=>`${d(o[i])} AS "${t[i]}"`);n.push(`(SELECT ${s.join(", ")})`)}return n.join(" UNION ALL ")}export{S as Query,y as Ref,Bt as agg,tt as all,st as and,we as argmax,Se as argmin,Ae as arrayAgg,l as asColumn,D as asRelation,Qt as avg,B as cast,Te as castDouble,be as castInteger,W as column,St as contains,ue as corr,Wt as count,le as covarPop,O as create,Pt as cume_dist,Ie as dateDay,Le as dateMonth,Oe as dateMonthDay,Ct as dense_rank,nt as desc,ie as entropy,qe as epoch_ms,pt as eq,Ne as first,Gt as first_value,ht as gt,xt as gte,$t as isBetween,Et as isDistinct,Lt as isFinite,Ot as isInfinite,qt as isNaN,Nt as isNotBetween,dt as isNotDistinct,lt as isNotNull,ut as isNull,b as isParamLike,G as isQuery,M as isSQLExpression,se as kurtosis,Mt as lag,ye as last,jt as last_value,Ft as lead,bt as length,ot as literal,d as literalToSQL,Ce as loadCSV,_e as loadJSON,Pe as loadParquet,At as lower,mt as lt,gt as lte,vt as mad,Ht as max,kt as mean,Zt as median,Kt as min,ee as mode,ft as neq,at as not,Yt as nth_value,Ut as ntile,it as or,_t as percent_rank,wt as prefix,Jt as product,te as quantile,Dt as rank,yt as regexp_matches,de as regrAvgX,$e as regrAvgY,me as regrCount,pe as regrIntercept,he as regrR2,xe as regrSXX,Ee as regrSXY,ge as regrSYY,fe as regrSlope,V as relation,It as row_number,oe as skewness,u as sql,Ue as sqlFrom,ne as stddev,ae as stddevPop,Re as stringAgg,Rt as suffix,zt as sum,et as toSQL,Tt as upper,ce as varPop,re as variance};
var w=class{constructor(t,e){t&&(this.table=String(t)),e&&(this.column=e)}get columns(){return this.column?[this.column]:[]}toString(){let{table:t,column:e}=this;if(e){let n=e.startsWith("*")?e:`"${e}"`;return`${t?`"${t}".`:""}${n}`}else return t?`"${t}"`:"NULL"}};function B(r,t){return r instanceof w&&r.column===t}function l(r){return typeof r=="string"?X(r):r}function _(r){return typeof r=="string"?V(r):r}function V(r){return new w(r)}function X(r,t){return arguments.length===1&&(t=r,r=null),new w(r,t)}function et(r){return new w(r,"*")}function rt(r){return typeof r=="string"?`"${r}"`:E(r)}function E(r){switch(typeof r){case"boolean":return r?"TRUE":"FALSE";case"string":return`'${r}'`;case"number":return Number.isFinite(r)?String(r):"NULL";default:if(r==null)return"NULL";if(r instanceof Date){let t=+r;if(Number.isNaN(t))return"NULL";let e=r.getUTCFullYear(),n=r.getUTCMonth(),o=r.getUTCDate();return t===Date.UTC(e,n,o)?`MAKE_DATE(${e}, ${n+1}, ${o})`:`EPOCH_MS(${t})`}else return r instanceof RegExp?`'${r.source}'`:String(r)}}var q=r=>typeof r?.addEventListener=="function";function U(r){return r instanceof A}var A=class{constructor(t,e,n){this._expr=Array.isArray(t)?t:[t],this._deps=e||[],this.annotate(n);let o=this._expr.filter(s=>q(s));o.length>0?(this._params=Array.from(new Set(o)),this._params.forEach(s=>{s.addEventListener("value",()=>nt(this,this.map?.get("value")))})):this.addEventListener=void 0}get value(){return this}get columns(){let{_params:t,_deps:e}=this;if(t){let n=new Set(t.flatMap(o=>{let s=o.value?.columns;return Array.isArray(s)?s:[]}));if(n.size){let o=new Set(e);return n.forEach(s=>o.add(s)),Array.from(o)}}return e}get column(){return this._deps.length?this._deps[0]:this.columns[0]}annotate(...t){return Object.assign(this,...t)}toString(){return this._expr.map(t=>q(t)&&!U(t)?E(t.value):t).join("")}addEventListener(t,e){let n=this.map||(this.map=new Map);(n.get(t)||(n.set(t,new Set),n.get(t))).add(e)}};function nt(r,t){if(t?.size)return Promise.allSettled(Array.from(t,e=>e(r)))}function j(r,t){let e=[r[0]],n=new Set,o=t.length;for(let s=0,i=0;s<o;){let c=t[s];q(c)?e[++i]=c:(Array.isArray(c?.columns)&&c.columns.forEach(g=>n.add(g)),e[i]+=typeof c=="string"?c:E(c));let p=r[++s];q(e[i])?e[++i]=p:e[i]+=p}return{spans:e,cols:Array.from(n)}}function u(r,...t){let{spans:e,cols:n}=j(r,t);return new A(e,n)}function ot(r){let t=l(r);return u`${t} DESC NULLS LAST`.annotate({label:t?.label,desc:!0})}var st=r=>({value:r,toString:()=>E(r)});function P(r){r(this.op,this),this.children?.forEach(t=>t.visit(r))}function Q(r,t){let e=t.filter(o=>o!=null).map(l),n=e.map((o,s)=>s?` ${r} `:"");return t.length&&n.push(""),u(n,...e).annotate({op:r,children:e,visit:P})}var it=(...r)=>Q("AND",r.flat()),ct=(...r)=>Q("OR",r.flat()),at=r=>t=>u`(${r} ${l(t)})`.annotate({op:r,a:t,visit:P}),ut=at("NOT"),k=r=>t=>u`(${l(t)} ${r})`.annotate({op:r,a:t,visit:P}),lt=k("IS NULL"),pt=k("IS NOT NULL"),T=r=>(t,e)=>u`(${l(t)} ${r} ${l(e)})`.annotate({op:r,a:t,b:e,visit:P}),ft=T("="),ht=T("<>"),mt=T("<"),gt=T(">"),xt=T("<="),dt=T(">="),Et=T("IS DISTINCT FROM"),$t=T("IS NOT DISTINCT FROM");function v(r,t,e,n){t=l(t);let o=r.startsWith("NOT ")?"NOT ":"";return(e?n?u`${o}(${e[0]} <= ${t} AND ${t} < ${e[1]})`:u`(${t} ${r} ${e[0]} AND ${e[1]})`:u``).annotate({op:r,visit:P,field:t,range:e})}var Nt=(r,t,e)=>v("BETWEEN",r,t,e),yt=(r,t,e)=>v("NOT BETWEEN",r,t,e);function L(r,t){return Array.from({length:r},()=>t)}function x(r,t){return(...e)=>{let n=e.map(l),o=t?`::${t}`:"";return(n.length?u([`${r}(`,...L(n.length-1,", "),`)${o}`],...n):u`${r}()${o}`).annotate({func:r,args:n})}}var wt=x("REGEXP_MATCHES"),St=x("CONTAINS"),Rt=x("PREFIX"),At=x("SUFFIX"),Tt=x("LOWER"),bt=x("UPPER"),qt=x("LENGTH"),Lt=x("ISNAN"),Ot=x("ISFINITE"),It=x("ISINF");var $=class extends A{constructor(t,e,n,o,s="",i="",c=""){let p;if(o&&!(s||i||c))p=o?u`${e} OVER "${o}"`:u`${e} OVER ()`;else{let I=s&&i?" ":"",D=(s||i)&&c?" ":"";p=u`${e} OVER (${o?`"${o}" `:""}${s}${I}${i}${D}${c})`}n&&(p=u`(${p})::${n}`);let{_expr:y,_deps:b}=p;super(y,b,{window:t,func:e,type:n,name:o,group:s,order:i,frame:c})}get basis(){return this.column}get label(){let{func:t}=this;return t.label??t.toString()}over(t){let{window:e,func:n,type:o,group:s,order:i,frame:c}=this;return new $(e,n,o,t,s,i,c)}partitionby(...t){let e=t.flat().filter(y=>y).map(l),n=u(["PARTITION BY ",L(e.length-1,", "),""],...e),{window:o,func:s,type:i,name:c,order:p,frame:g}=this;return new $(o,s,i,c,n,p,g)}orderby(...t){let e=t.flat().filter(y=>y).map(l),n=u(["ORDER BY ",L(e.length-1,", "),""],...e),{window:o,func:s,type:i,name:c,group:p,frame:g}=this;return new $(o,s,i,c,p,n,g)}rows(t){let e=H("ROWS",t),{window:n,func:o,type:s,name:i,group:c,order:p}=this;return new $(n,o,s,i,c,p,e)}range(t){let e=H("RANGE",t),{window:n,func:o,type:s,name:i,group:c,order:p}=this;return new $(n,o,s,i,c,p,e)}};function H(r,t){if(q(t)){let e=u`${t}`;return e.toString=()=>`${r} ${K(t.value)}`,e}return`${r} ${K(t)}`}function K(r){let[t,e]=r,n=t===0?"CURRENT ROW":Number.isFinite(t)?`${Math.abs(t)} PRECEDING`:"UNBOUNDED PRECEDING",o=e===0?"CURRENT ROW":Number.isFinite(e)?`${Math.abs(e)} FOLLOWING`:"UNBOUNDED FOLLOWING";return`BETWEEN ${n} AND ${o}`}function N(r,t){return(...e)=>{let n=x(r)(...e);return new $(r,n,t)}}var Dt=N("ROW_NUMBER","INTEGER"),Ct=N("RANK","INTEGER"),_t=N("DENSE_RANK","INTEGER"),Pt=N("PERCENT_RANK"),Ut=N("CUME_DIST"),Mt=N("NTILE"),Ft=N("LAG"),Gt=N("LEAD"),jt=N("FIRST_VALUE"),Yt=N("LAST_VALUE"),Wt=N("NTH_VALUE");function Bt(r,...t){return u(r,...t).annotate({aggregate:!0})}var O=class extends A{constructor(t,e,n,o,s){e=(e||[]).map(l);let{strings:i,exprs:c}=Vt(t,e,n,o,s),{spans:p,cols:g}=j(i,c);super(p,g,{aggregate:t,args:e,type:n,isDistinct:o,filter:s})}get basis(){return this.column}get label(){let{aggregate:t,args:e,isDistinct:n}=this,o=n?"DISTINCT"+(e.length?" ":""):"",s=e.length?`(${o}${e.map(Xt).join(", ")})`:"";return`${t.toLowerCase()}${s}`}distinct(){let{aggregate:t,args:e,type:n,filter:o}=this;return new O(t,e,n,!0,o)}where(t){let{aggregate:e,args:n,type:o,isDistinct:s}=this;return new O(e,n,o,s,t)}window(){let{aggregate:t,args:e,type:n,isDistinct:o}=this,s=new O(t,e,null,o);return new $(t,s,n)}partitionby(...t){return this.window().partitionby(...t)}orderby(...t){return this.window().orderby(...t)}rows(t,e){return this.window().rows(t,e)}range(t,e){return this.window().range(t,e)}};function Vt(r,t,e,n,o){let s=`)${e?`::${e}`:""}`,i=[`${r}(${n?"DISTINCT ":""}`],c=[];return t.length?(i=i.concat([...L(t.length-1,", "),`${s}${o?" FILTER (WHERE ":""}`,...o?[")"]:[]]),c=[...t,...o?[o]:[]]):i[0]+="*"+s,{exprs:c,strings:i}}function Xt(r){let t=E(r);return t&&t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function a(r,t){return(...e)=>new O(r,e,t)}var Qt=a("COUNT","INTEGER"),kt=a("AVG"),vt=a("AVG"),Ht=a("MAD"),Kt=a("MAX"),zt=a("MIN"),Jt=a("SUM","DOUBLE"),Zt=a("PRODUCT"),te=a("MEDIAN"),ee=a("QUANTILE"),re=a("MODE"),ne=a("VARIANCE"),oe=a("STDDEV"),se=a("SKEWNESS"),ie=a("KURTOSIS"),ce=a("ENTROPY"),ae=a("VAR_POP"),ue=a("STDDEV_POP"),le=a("CORR"),pe=a("COVAR_POP"),fe=a("REGR_INTERCEPT"),he=a("REGR_SLOPE"),me=a("REGR_COUNT"),ge=a("REGR_R2"),xe=a("REGR_SYY"),de=a("REGR_SXX"),Ee=a("REGR_SXY"),$e=a("REGR_AVGX"),Ne=a("REGR_AVGY"),ye=a("FIRST"),we=a("LAST"),Se=a("ARG_MIN"),Re=a("ARG_MAX"),Ae=a("STRING_AGG"),Te=a("ARRAY_AGG");function Y(r,t){let e=l(r),n=u`CAST(${e} AS ${t})`;return Object.defineProperty(n,"label",{enumerable:!0,get(){return r.label}}),Object.defineProperty(n,"aggregate",{enumerable:!0,get(){return r.aggregate||!1}}),n}var be=r=>Y(r,"DOUBLE"),qe=r=>Y(r,"INTEGER");var Le=r=>{let t=l(r);return u`(1000 * (epoch(${t}) - second(${t})) + millisecond(${t}))::DOUBLE`},Oe=r=>{let t=l(r);return u`MAKE_DATE(2012, MONTH(${t}), 1)`.annotate({label:"month"})},Ie=r=>{let t=l(r);return u`MAKE_DATE(2012, MONTH(${t}), DAY(${t}))`.annotate({label:"date"})},De=r=>{let t=l(r);return u`MAKE_DATE(2012, 1, DAY(${t}))`.annotate({label:"date"})};var S=class{static select(...t){return new S().select(...t)}static from(...t){return new S().from(...t)}static with(...t){return new S().with(...t)}static union(...t){return new R("UNION",t.flat())}static unionAll(...t){return new R("UNION ALL",t.flat())}static intersect(...t){return new R("INTERSECT",t.flat())}static except(...t){return new R("EXCEPT",t.flat())}constructor(){this.query={with:[],select:[],from:[],where:[],groupby:[],having:[],window:[],qualify:[],orderby:[]}}clone(){let t=new S;return t.query={...this.query},t}with(...t){let{query:e}=this;if(t.length===0)return e.with;{let n=[],o=(s,i)=>{let c=i.clone();c.cteFor=this,n.push({as:s,query:c})};return t.flat().forEach(s=>{if(s!=null)if(s.as&&s.query)o(s.as,s.query);else for(let i in s)o(i,s[i])}),e.with=e.with.concat(n),this}}select(...t){let{query:e}=this;if(t.length===0)return e.select;{let n=[];for(let o of t.flat())if(o!=null)if(typeof o=="string")n.push({as:o,expr:l(o)});else if(o instanceof w)n.push({as:o.column,expr:o});else if(Array.isArray(o))n.push({as:o[0],expr:o[1]});else for(let s in o)n.push({as:M(s),expr:l(o[s])});return e.select=e.select.concat(n),this}}$select(...t){return this.query.select=[],this.select(...t)}distinct(t=!0){return this.query.distinct=!!t,this}from(...t){let{query:e}=this;if(t.length===0)return e.from;{let n=[];return t.flat().forEach(o=>{if(o!=null)if(typeof o=="string")n.push({as:o,from:_(o)});else if(o instanceof w)n.push({as:o.table,from:o});else if(F(o)||U(o))n.push({from:o});else if(Array.isArray(o))n.push({as:M(o[0]),from:_(o[1])});else for(let s in o)n.push({as:M(s),from:_(o[s])})}),e.from=e.from.concat(n),this}}$from(...t){return this.query.from=[],this.from(...t)}sample(t,e){let{query:n}=this;if(arguments.length===0)return n.sample;{let o=t;return typeof t=="number"&&(o=t>0&&t<1?{perc:100*t,method:e}:{rows:Math.round(t),method:e}),n.sample=o,this}}where(...t){let{query:e}=this;return t.length===0?e.where:(e.where=e.where.concat(t.flat().filter(n=>n)),this)}$where(...t){return this.query.where=[],this.where(...t)}groupby(...t){let{query:e}=this;return t.length===0?e.groupby:(e.groupby=e.groupby.concat(t.flat().filter(n=>n).map(l)),this)}$groupby(...t){return this.query.groupby=[],this.groupby(...t)}having(...t){let{query:e}=this;return t.length===0?e.having:(e.having=e.having.concat(t.flat().filter(n=>n)),this)}window(...t){let{query:e}=this;if(t.length===0)return e.window;{let n=[];return t.flat().forEach(o=>{if(o!=null)for(let s in o)n.push({as:M(s),expr:o[s]})}),e.window=e.window.concat(n),this}}qualify(...t){let{query:e}=this;return t.length===0?e.qualify:(e.qualify=e.qualify.concat(t.flat().filter(n=>n)),this)}orderby(...t){let{query:e}=this;return t.length===0?e.orderby:(e.orderby=e.orderby.concat(t.flat().filter(n=>n).map(l)),this)}limit(t){let{query:e}=this;return arguments.length===0?e.limit:(e.limit=Number.isFinite(t)?t:void 0,this)}offset(t){let{query:e}=this;return arguments.length===0?e.offset:(e.offset=Number.isFinite(t)?t:void 0,this)}get subqueries(){let{query:t,cteFor:e}=this,o=(e?.query||t).with?.reduce((i,{as:c,query:p})=>(i[c]=p,i),{}),s=[];return t.from.forEach(({from:i})=>{if(F(i))s.push(i);else if(o[i.table]){let c=o[i.table];s.push(c)}}),s}toString(){let{select:t,distinct:e,from:n,sample:o,where:s,groupby:i,having:c,window:p,qualify:g,orderby:y,limit:b,offset:I,with:D}=this.query,m=[];if(D.length){let f=D.map(({as:h,query:d})=>`"${h}" AS (${d})`);m.push(`WITH ${f.join(", ")}`)}let J=t.map(({as:f,expr:h})=>B(h,f)&&!h.table?`${h}`:`${h} AS "${f}"`);if(m.push(`SELECT${e?" DISTINCT":""} ${J.join(", ")}`),n.length){let f=n.map(({as:h,from:d})=>{let C=F(d)?`(${d})`:`${d}`;return!h||h===d.table?C:`${C} AS "${h}"`});m.push(`FROM ${f.join(", ")}`)}if(s.length){let f=s.map(String).filter(h=>h).join(" AND ");f&&m.push(`WHERE ${f}`)}if(o){let{rows:f,perc:h,method:d,seed:C}=o,Z=f?`${f} ROWS`:`${h} PERCENT`,tt=d?` (${d}${C!=null?`, ${C}`:""})`:"";m.push(`USING SAMPLE ${Z}${tt}`)}if(i.length&&m.push(`GROUP BY ${i.join(", ")}`),c.length){let f=c.map(String).filter(h=>h).join(" AND ");f&&m.push(`HAVING ${f}`)}if(p.length){let f=p.map(({as:h,expr:d})=>`"${h}" AS (${d})`);m.push(`WINDOW ${f.join(", ")}`)}if(g.length){let f=g.map(String).filter(h=>h).join(" AND ");f&&m.push(`QUALIFY ${f}`)}return y.length&&m.push(`ORDER BY ${y.join(", ")}`),Number.isFinite(b)&&m.push(`LIMIT ${b}`),Number.isFinite(I)&&m.push(`OFFSET ${I}`),m.join(" ")}},R=class{constructor(t,e){this.op=t,this.queries=e.map(n=>n.clone()),this.query={orderby:[]}}clone(){let t=new R(this.op,this.queries);return t.query={...this.query},t}orderby(...t){let{query:e}=this;return t.length===0?e.orderby:(e.orderby=e.orderby.concat(t.flat().filter(n=>n).map(l)),this)}limit(t){let{query:e}=this;return arguments.length===0?e.limit:(e.limit=Number.isFinite(t)?t:void 0,this)}offset(t){let{query:e}=this;return arguments.length===0?e.offset:(e.offset=Number.isFinite(t)?t:void 0,this)}get subqueries(){let{queries:t,cteFor:e}=this;return e&&t.forEach(n=>n.cteFor=e),t}toString(){let{op:t,queries:e,query:{orderby:n,limit:o,offset:s}}=this,i=[e.join(` ${t} `)];return n.length&&i.push(`ORDER BY ${n.join(", ")}`),Number.isFinite(o)&&i.push(`LIMIT ${o}`),Number.isFinite(s)&&i.push(`OFFSET ${s}`),i.join(" ")}};function F(r){return r instanceof S||r instanceof R}function M(r){return Ce(r)?r.slice(1,-1):r}function Ce(r){return r[0]==='"'&&r[r.length-1]==='"'}function G(r,t,{replace:e=!1,temp:n=!0,view:o=!1}={}){return"CREATE"+(e?" OR REPLACE ":" ")+(n?"TEMP ":"")+(o?"VIEW":"TABLE")+(e?" ":" IF NOT EXISTS ")+r+" AS "+t}function z(r,{columns:t=Object.keys(r?.[0]||{})}={}){let e=[];if(Array.isArray(t)?(e=t,t=e.reduce((o,s)=>(o[s]=s,o),{})):t&&(e=Object.keys(t)),!e.length)throw new Error("Can not create table from empty column set.");let n=[];for(let o of r){let s=e.map(i=>`${E(o[i])} AS "${t[i]}"`);n.push(`(SELECT ${s.join(", ")})`)}return n.join(" UNION ALL ")}function W(r,t,e,n={},o={}){let{select:s=["*"],where:i,view:c,temp:p,replace:g,...y}=n,b=Fe({...o,...y}),I=`${r}('${e}'${b?", "+b:""})`,D=i?` WHERE ${i}`:"",m=`SELECT ${s.join(", ")} FROM ${I}${D}`;return G(t,m,{view:c,temp:p,replace:g})}function _e(r,t,e){return W("read_csv",r,t,e,{auto_detect:!0,sample_size:-1})}function Pe(r,t,e){return W("read_json",r,t,e,{auto_detect:!0,json_format:"auto"})}function Ue(r,t,e){return W("read_parquet",r,t,e)}function Me(r,t,e={}){let{select:n=["*"],...o}=e,s=z(t),i=n.length===1&&n[0]==="*"?s:`SELECT ${n} FROM ${s}`;return G(r,i,o)}function Fe(r){return Object.entries(r).map(([t,e])=>{let n=typeof e,o=n==="boolean"?String(e):n==="string"?`'${e}'`:e;return`${t}=${o}`}).join(", ")}export{S as Query,w as Ref,Bt as agg,et as all,it as and,Re as argmax,Se as argmin,Te as arrayAgg,l as asColumn,_ as asRelation,kt as avg,Y as cast,be as castDouble,qe as castInteger,X as column,St as contains,le as corr,Qt as count,pe as covarPop,G as create,Ut as cume_dist,De as dateDay,Oe as dateMonth,Ie as dateMonthDay,_t as dense_rank,ot as desc,ce as entropy,Le as epoch_ms,ft as eq,ye as first,jt as first_value,gt,dt as gte,Nt as isBetween,Et as isDistinct,Ot as isFinite,It as isInfinite,Lt as isNaN,yt as isNotBetween,$t as isNotDistinct,pt as isNotNull,lt as isNull,q as isParamLike,F as isQuery,U as isSQLExpression,ie as kurtosis,Ft as lag,we as last,Yt as last_value,Gt as lead,qt as length,st as literal,E as literalToSQL,_e as loadCSV,Pe as loadJSON,Me as loadObjects,Ue as loadParquet,Tt as lower,mt as lt,xt as lte,Ht as mad,Kt as max,vt as mean,te as median,zt as min,re as mode,ht as neq,ut as not,Wt as nth_value,Mt as ntile,ct as or,Pt as percent_rank,Rt as prefix,Zt as product,ee as quantile,Ct as rank,wt as regexp_matches,$e as regrAvgX,Ne as regrAvgY,me as regrCount,fe as regrIntercept,ge as regrR2,de as regrSXX,Ee as regrSXY,xe as regrSYY,he as regrSlope,V as relation,Dt as row_number,se as skewness,u as sql,oe as stddev,ue as stddevPop,Ae as stringAgg,At as suffix,Jt as sum,rt as toSQL,bt as upper,ae as varPop,ne as variance};
{
"name": "@uwdata/mosaic-sql",
"version": "0.2.0",
"version": "0.3.0",
"description": "SQL query construction and analysis.",

@@ -28,3 +28,3 @@ "keywords": [

},
"gitHead": "e53cd914c807f99aabe78dcbe618dd9543e2f438"
"gitHead": "a8dd23fed4c7a24c0a2ee5261d1aabe4239ce574"
}

@@ -132,5 +132,7 @@ export {

export { create } from './load/create.js';
export { loadCSV } from './load/csv.js';
export { loadJSON } from './load/json.js';
export { loadParquet } from './load/parquet.js';
export { sqlFrom } from './load/sql-from.js';
export {
loadCSV,
loadJSON,
loadObjects,
loadParquet
} from './load/load.js';

@@ -1,6 +0,12 @@

export function create(name, query, options = {}) {
const { temp, replace, type = 'TABLE' } = options;
const create = `CREATE${replace ? ' OR REPLACE' : ''}`;
const spec = `${temp ? 'TEMP ' : ''}${type}${replace ? '' : ' IF NOT EXISTS'}`;
return `${create} ${spec} ${name} AS ${query}`;
export function create(name, query, {
replace = false,
temp = true,
view = false
} = {}) {
return 'CREATE'
+ (replace ? ' OR REPLACE ' : ' ')
+ (temp ? 'TEMP ' : '')
+ (view ? 'VIEW' : 'TABLE')
+ (replace ? ' ' : ' IF NOT EXISTS ')
+ name + ' AS ' + query;
}

@@ -159,3 +159,3 @@ import { isSQLExpression } from './expression.js';

? { perc: 100 * value, method }
: { rows: Math.round(value, method) };
: { rows: Math.round(value), method };
}

@@ -196,2 +196,7 @@ query.sample = spec;

$groupby(...expr) {
this.query.groupby = [];
return this.groupby(...expr);
}
having(...expr) {

@@ -198,0 +203,0 @@ const { query } = this;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc