From 8fe1b23515d85cbaf6ffe0f7dc2668b2c3fc5dc6 Mon Sep 17 00:00:00 2001 From: Nael Shiab Date: Fri, 9 Aug 2024 08:46:39 -0400 Subject: [PATCH] Updating doc --- docs/classes/SimpleDB.html | 46 +++--- docs/classes/SimpleTable.html | 269 ++++++++++++++++--------------- docs/classes/SimpleWebDB.html | 44 ++--- docs/classes/SimpleWebTable.html | 254 ++++++++++++++--------------- docs/hierarchy.html | 2 +- docs/index.html | 4 +- docs/modules.html | 4 +- 7 files changed, 312 insertions(+), 311 deletions(-) diff --git a/docs/classes/SimpleDB.html b/docs/classes/SimpleDB.html index 9c9d29e4..63e2e798 100644 --- a/docs/classes/SimpleDB.html +++ b/docs/classes/SimpleDB.html @@ -1,4 +1,4 @@ -SimpleDB | Simple-data-analysis - v3.6.2

SimpleDB is a class that provides a simplified interface for working with DuckDB, a high-performance, in-memory analytical database. This class is meant to be used with NodeJS and similar runtimes. For web browsers, use SimpleWebDB.

+SimpleDB | Simple-data-analysis - v3.6.3

SimpleDB is a class that provides a simplified interface for working with DuckDB, a high-performance, in-memory analytical database. This class is meant to be used with NodeJS and similar runtimes. For web browsers, use SimpleWebDB.

With very expensive computations, it might create a .tmp folder, so make sure to add .tmp to your gitignore.

Here's how to instantiate a SimpleDB instance and then a SimpleTable.

// Instantiating the database.
const sdb = new SimpleDB()

// Creating a new table.
const employees = sdb.newTable("employees")

// You can now invoke methods on the table.
await employees.loadData("./employees.csv")
await employees.logTable()

// To free up memory.
await sdb.done() @@ -7,7 +7,7 @@
// Creating a database with options. Debug information will be logged each time a method is invoked. The first 20 rows of tables will be logged (default is 10).
const sdb = new SimpleWebDB({ debug: true, nbRowsToLog: 20 })
-

Hierarchy (view full)

Properties

Hierarchy (view full)

Properties

Internal

Properties

bigIntToInt: undefined | boolean

A flag for SimpleDB. Default is true. When data is retrieved from the database as an array of objects, BIGINT values are automatically converted to integers, which are easier to work with in JavaScript. If you want actual bigint values, set this option to false.

-
cacheSourcesUsed: string[]

An object keeping track of the data used in cache.

-
connection: AsyncDuckDBConnection | Connection

A connection to a DuckDB database.

-
db: AsyncDuckDB | Database

A DuckDB database.

-
debug: boolean

A flag indicating whether debugging information should be logged. Defaults to false.

-
defaultTableName: boolean

A flag to know if the name of the table has been attributed by default.

-
durationStart: undefined | number

A timestamp used to track the total duration logged in done().

-
nbCharactersToLog: undefined | number

The number of characters to log for text cells. By default, the whole text is logged.

-
nbRowsToLog: number

The number of rows to log. Defaults to 10.

-
runQuery: ((query: string, connection: AsyncDuckDBConnection | Connection, returnDataFromQuery: boolean, options: {
    bigIntToInt?: boolean;
    debug: boolean;
    method: null | string;
    parameters: null | {
        [key: string]: unknown;
    };
}) => Promise<null | {
    [key: string]:
        | number
        | string
        | Date
        | boolean
        | null;
}[]>)

For internal use only. If you want to run a SQL query, use the customQuery method.

-
tableIncrement: number

A number used when creating new tables.

-
worker: null | Worker

A worker to make DuckDB WASM work.

-

Other

cacheVerbose: boolean

A flag to log messages relative to the cache. Defaults to false.

-

DB methods

  • Executes a custom SQL query, providing flexibility for advanced users.

    +
cacheSourcesUsed: string[]

An object keeping track of the data used in cache.

+
connection: AsyncDuckDBConnection | Connection

A connection to a DuckDB database.

+
db: AsyncDuckDB | Database

A DuckDB database.

+
debug: boolean

A flag indicating whether debugging information should be logged. Defaults to false.

+
defaultTableName: boolean

A flag to know if the name of the table has been attributed by default.

+
durationStart: undefined | number

A timestamp used to track the total duration logged in done().

+
nbCharactersToLog: undefined | number

The number of characters to log for text cells. By default, the whole text is logged.

+
nbRowsToLog: number

The number of rows to log. Defaults to 10.

+
runQuery: ((query: string, connection: AsyncDuckDBConnection | Connection, returnDataFromQuery: boolean, options: {
    bigIntToInt?: boolean;
    debug: boolean;
    method: null | string;
    parameters: null | {
        [key: string]: unknown;
    };
}) => Promise<null | {
    [key: string]:
        | number
        | string
        | Date
        | boolean
        | null;
}[]>)

For internal use only. If you want to run a SQL query, use the customQuery method.

+
tableIncrement: number

A number used when creating new tables.

+
worker: null | Worker

A worker to make DuckDB WASM work.

+

Other

cacheVerbose: boolean

A flag to log messages relative to the cache. Defaults to false.

+

DB methods

  • Frees up memory by closing down the database and cleans up cache so it doesn't grow in size indefinitely.

    Returns Promise<void>

    await sdb.done();
     
    -
  • Returns the DuckDB extensions.

    +
  • Returns the DuckDB extensions.

    const extensions = await sdb.getExtensions()
     
    -

    Returns Promise<{
        [key: string]:
            | string
            | number
            | boolean
            | Date
            | null;
    }[]>

  • Returns the list of tables.

    +

    Returns Promise<{
        [key: string]:
            | string
            | number
            | boolean
            | Date
            | null;
    }[]>

  • Returns true if a specified table exists and false if not.

    Parameters

    • table: string

      The name of the table to check for existence.

    Returns Promise<boolean>

    const hasEmployees = await sdb.hasTable("employees")
     
    -
  • Creates a table in the DB.

    Parameters

    • Optionalname: string

      The name of the new table.

    • Optionalprojections: {
          [key: string]: string;
      }

      The projections of the geospatial data, if any.

      • [key: string]: string

    Returns SimpleTable

    // This returns a new SimpleTable
    const employees = sdb.newTable() @@ -75,7 +75,7 @@
    // By default, tables will be named table1, table2, etc.
    // But you can also give them specific names.
    const employees = sdb.newTable("employees")
    -
  • Remove a table or multiple tables from the database. Invoking methods on the tables will throw and error.

    +
  • Remove a table or multiple tables from the database. Invoking methods on the tables will throw and error.

    Parameters

    Returns Promise<void>

    await table.removeTables(tableA)
     
    @@ -83,5 +83,5 @@
    await table.removeTables([tableA, tableB])
     
    -

Internal

+

Internal

diff --git a/docs/classes/SimpleTable.html b/docs/classes/SimpleTable.html index 465523b1..f12183ac 100644 --- a/docs/classes/SimpleTable.html +++ b/docs/classes/SimpleTable.html @@ -1,11 +1,11 @@ -SimpleTable | Simple-data-analysis - v3.6.2

SimpleTable is a class representing a table in a SimpleDB. It can handle tabular and geospatial data. To create one, it's best to instantiate a SimpleDB first.

+SimpleTable | Simple-data-analysis - v3.6.3

SimpleTable is a class representing a table in a SimpleDB. It can handle tabular and geospatial data. To create one, it's best to instantiate a SimpleDB first.

// Creating a database first.
const sdb = new SimpleDB()

// Making a new table. This returns a SimpleTable.
const employees = sdb.newTable()

// You can now invoke methods on the table.
await employees.loadData("./employees.csv")
await employees.logTable()

// Removing the DB to free up memory.
await sdb.done()
// To load geospatial data, use .loadGeoData instead of .loadData
const boundaries = sdb.newTable()
await boundaries.loadGeoData("./boundaries.geojson")
-

Hierarchy (view full)

Properties

Hierarchy (view full)

Properties

Properties

bigIntToInt: undefined | boolean

A flag for SimpleDB. Default is true. When data is retrieved from the database as an array of objects, BIGINT values are automatically converted to integers, which are easier to work with in JavaScript. If you want actual bigint values, set this option to false.

-
connection: AsyncDuckDBConnection | Connection

A connection to a DuckDB database.

-
db: AsyncDuckDB | Database

A DuckDB database.

-
debug: boolean

A flag indicating whether debugging information should be logged. Defaults to false.

-
defaultTableName: boolean

A flag to know if the name of the table has been attributed by default.

-
name: string

Name of the table in the database.

-
nbCharactersToLog: undefined | number

The number of characters to log for text cells. By default, the whole text is logged.

-
nbRowsToLog: number

The number of rows to log. Defaults to 10.

-
projections: {
    [key: string]: string;
}

The projections of the geospatial data, if any.

-
runQuery: ((query: string, connection: AsyncDuckDBConnection | Connection, returnDataFromQuery: boolean, options: {
    bigIntToInt?: boolean;
    debug: boolean;
    method: null | string;
    parameters: null | {
        [key: string]: unknown;
    };
}) => Promise<null | {
    [key: string]:
        | number
        | string
        | Date
        | boolean
        | null;
}[]>)

For internal use only. If you want to run a SQL query, use the customQuery method.

-

The SimpleDB that created this table.

-
tableIncrement: number

A number used when creating new tables.

-
worker: null | Worker

A worker to make DuckDB WASM work.

-

Analyzing data

connection: AsyncDuckDBConnection | Connection

A connection to a DuckDB database.

+
db: AsyncDuckDB | Database

A DuckDB database.

+
debug: boolean

A flag indicating whether debugging information should be logged. Defaults to false.

+
defaultTableName: boolean

A flag to know if the name of the table has been attributed by default.

+
name: string

Name of the table in the database.

+
nbCharactersToLog: undefined | number

The number of characters to log for text cells. By default, the whole text is logged.

+
nbRowsToLog: number

The number of rows to log. Defaults to 10.

+
projections: {
    [key: string]: string;
}

The projections of the geospatial data, if any.

+
runQuery: ((query: string, connection: AsyncDuckDBConnection | Connection, returnDataFromQuery: boolean, options: {
    bigIntToInt?: boolean;
    debug: boolean;
    method: null | string;
    parameters: null | {
        [key: string]: unknown;
    };
}) => Promise<null | {
    [key: string]:
        | number
        | string
        | Date
        | boolean
        | null;
}[]>)

For internal use only. If you want to run a SQL query, use the customQuery method.

+

The SimpleDB that created this table.

+
tableIncrement: number

A number used when creating new tables.

+
worker: null | Worker

A worker to make DuckDB WASM work.

+

Analyzing data

  • Assigns bins for specified column values based on an interval size.

    Parameters

    • values: string

      The column containing values from which bins will be computed.

    • interval: number

      The interval size for binning the values.

    • newColumn: string

      The name of the new column where the bins will be stored.

      @@ -161,7 +161,7 @@
  • Calculates correlations between columns.

    If no x and y columns are specified, the method computes the correlations of all numeric columns combinations. It's important to note that correlation is symmetrical: the correlation of x over y is the same as y over x.

    Parameters

    • options: {
          categories?: string | string[];
          decimals?: number;
          outputTable?: string | boolean;
          x?: string;
          y?: string;
      } = {}

      An optional object with configuration options:

      • Optionalcategories?: string | string[]

        The column or columns that define categories. Correlation calculations will be run for each category.

        @@ -184,7 +184,7 @@
        // Same but results are stored in tableB.
        const tableB = await table.correlations({ outputTable: "tableB" })
        -
  • Performs linear regression analysis. The results include the slope, the y-intercept the R-squared.

    If no x and y columns are specified, the method computes the linear regression analysis of all numeric columns permutations. It's important to note that linear regression analysis is asymmetrical: the linear regression of x over y is not the same as y over x.

    Parameters

    • options: {
          categories?: string | string[];
          decimals?: number;
          outputTable?: string | boolean;
          x?: string;
          y?: string;
      } = {}

      An optional object with configuration options:

      • Optionalcategories?: string | string[]

        The column or columns that define categories. Correlation calculations will be run for each category.

        @@ -206,7 +206,7 @@
        // Same but stores the results in tableB.
        const tableB = await table.linearRegressions({ outputTable: "tableB" })
        -
  • Normalizes the values in a column using min-max normalization.

    Parameters

    • column: string

      The name of the column in which values will be normalized.

    • newColumn: string

      The name of the new column where normalized values will be stored.

    • options: {
          categories?: string | string[];
          decimals?: number;
      } = {}

      An optional object with configuration options:

      @@ -221,7 +221,7 @@
  • Identifies outliers using the Interquartile Range (IQR) method.

    Parameters

    • column: string

      The name of the column in which outliers will be identified.

    • newColumn: string

      The name of the new column where the bins will be stored.

    • options: {
          categories?: string | string[];
      } = {}

      An optional object with configuration options:

      @@ -232,7 +232,7 @@
  • Computes proportions within a row for specified columns.

    For example, let's say this is tableA.

    @@ -362,7 +362,7 @@
    @@ -1152,26 +1153,26 @@
    -
  • Removes one or more columns from this table.

    Parameters

    • columns: string | string[]

      The name or an array of names of the columns to be removed.

    Returns Promise<void>

    await table.removeColumns(["column1", "column2"])
     
    -
  • Remove the table from the database. Invoking methods on this table will throw and error.

    Returns Promise<void>

    await table.removeTable()
     
    -
  • Renames columns in the table.

    Parameters

    • names: {
          [key: string]: string;
      }

      An object mapping old column names to new column names.

      • [key: string]: string

    Returns Promise<void>

    // Renaming "How old?" to "age" and "Man or woman?" to "sex".
    await table.renameColumns({ "How old?" : "age", "Man or woman?": "sex" })
    -
  • Selects specific columns in the table and removes the others.

    Parameters

    • columns: string | string[]

      Either a string (one column) or an array of strings (multiple columns) representing the columns to be selected.

    Returns Promise<void>

    // Selecting only the columns firstName and lastName. All other columns in the table will be removed.
    await table.selectColumns([ "firstName", "lastName" ])
    -
  • Sorts the rows based on specified column(s) and order(s).

    Parameters

    • order: {
          [key: string]: "asc" | "desc";
      }

      An object mapping column names to the sorting order: "asc" for ascending or "desc" for descending.

      • [key: string]: "asc" | "desc"
    • options: {
          lang?: {
              [key: string]: string;
          };
      } = {}

      An optional object with configuration options:

Selecting or filtering data

Selecting or filtering data

  • Filters rows from this table based on SQL conditions. Note that it's often faster to use the removeRows method.

    Parameters

    • conditions: string

      The filtering conditions specified as a SQL WHERE clause.

    Returns Promise<void>

    // Keeps only rows where the fruit is not an apple.
    await table.filter(`fruit != 'apple'`)
    @@ -1266,23 +1267,23 @@
    await table.filter(`price > 100 AND quantity > 0`)
    await table.filter(`category = 'Electronics' OR category = 'Appliances'`)
    await table.filter(`lastPurchaseDate >= '2023-01-01'`)
    -
  • Keeps rows with specific values in specific columns.

    Parameters

    • columnsAndValues: {
          [key: string]: unknown[];
      }

      An object with the columns (keys) and the values to be kept (values as arrays)

      • [key: string]: unknown[]

    Returns Promise<void>

    // Keeps only rows where the job is 'accountant' or 'developer' and where the city is 'Montreal'.
    await table.keep({ job: ["accountant", "developer"], city: ["Montreal"] })
    -
  • Remove rows with specific values in specific columns.

    Parameters

    • columnsAndValues: {
          [key: string]: unknown[];
      }

      An object with the columns (keys) and the values to be removed (values as arrays)

      • [key: string]: unknown[]

    Returns Promise<void>

    // Remove rows where the job is 'accountant' or 'developer' and where the city is 'Montreal'.
    await table.remove({ job: ["accountant", "developer"], city: ["Montreal"] })
    -
  • Removes duplicate rows from this table, keeping unique rows. Note that SQL does not guarantee any specific order when using DISTINCT. So the data might be returned in a different order than the original.

    +
  • Removes duplicate rows from this table, keeping unique rows. Note that SQL does not guarantee any specific order when using DISTINCT. So the data might be returned in a different order than the original.

    Parameters

    • options: {
          on?: string | string[];
      } = {}

      An optional object with configuration options:

      • Optionalon?: string | string[]

        A column or multiple columns to consider to remove duplicates. The other columns in the table will not be considered to exclude duplicates.

    Returns Promise<void>

    await table.removeDuplicates("tableA")
     
    -
  • Removes rows with missing values from this table. By default, missing values are NULL (as an SQL value), but also "NULL", "null", "NaN" and "undefined" that might have been converted to strings before being loaded into the table. Empty strings "" are also considered missing values.

    +
  • Removes rows with missing values from this table. By default, missing values are NULL (as an SQL value), but also "NULL", "null", "NaN" and "undefined" that might have been converted to strings before being loaded into the table. Empty strings "" are also considered missing values.

    Parameters

    • options: {
          columns?: string | string[];
          invert?: boolean;
          missingValues?: (string | number)[];
      } = {}

      An optional object with configuration options:

      • Optionalcolumns?: string | string[]

        Either a string or an array of strings specifying the columns to consider for missing values. By default, all columns are considered.

      • Optionalinvert?: boolean

        A boolean indicating whether to invert the condition, keeping only rows with missing values. Defaults to false.

        @@ -1293,12 +1294,12 @@
        // Removes rows with missing values in specific columns.
        await table.removeMissing({ columns: ["firstName", "lastName"] })
        -
  • Removes rows from this table based on SQL conditions.

    Parameters

    • conditions: string

      The filtering conditions specified as a SQL WHERE clause.

    Returns Promise<void>

    // Removes rows where the fruit is an apple.
    await table.removeRows(`fruit = 'apple'`)
    -
  • Selects random rows from the table and removes the others. You can optionally specify a seed to ensure the same random rows are selected each time.

    +
  • Selects random rows from the table and removes the others. You can optionally specify a seed to ensure the same random rows are selected each time.

    Parameters

    • quantity: string | number

      The number of rows (1000 for example) or a string ("10%" for example) specifying the sampling size.

    • options: {
          seed?: number;
      } = {}

      An optional object with configuration options:

      • Optionalseed?: number

        A number specifying the seed for repeatable sampling. For example, setting it to 1 will ensure random rows will be the same each time you run the method.

        @@ -1311,7 +1312,7 @@
        // Selects always the same random rows
        await table.sample("10%", { seed: 1 })
        -
  • Selects n rows from this table. An offset and outputTable options are available.

    Parameters

    • count: string | number

      The number of rows.

    • options: {
          offset?: number;
          outputTable?: string | boolean;
      } = {}

      An optional object with configuration options:

      • Optionaloffset?: number

        The number of rows to skip before selecting. Defaults to 0.

        @@ -1328,12 +1329,12 @@
        // Selects 100 rows and stores them in a new table.
        const tableB = await tableA.selectRows(100, { outputTable: "tableB" })
        -
  • Skips the first X rows.

    Parameters

    • nbRowsToSkip: number

      The number of rows to skip.

    Returns Promise<void>

    // Skips the first 10 rows.
    await table.skip(10)
    -

Updating data

Updating data

  • Concatenates values from specified columns into a new column.

    Parameters

    • columns: string[]

      An array of column names from which values will be concatenated.

    • newColumn: string

      The name of the new column to store the concatenated values.

    • options: {
          separator?: string;
      } = {}

      An optional object with configuration options:

      @@ -1344,18 +1345,18 @@
      // Same thing, but the values will be separated by a dash
      await table.concatenate(["column1", "column2"], "column3", { separator: "-" })
      -
  • Fills cells containing NULL values. If a cell is empty, it's filled with the previous row's value.

    Parameters

    • columns: string | string[]

      The columns to fill.

    Returns Promise<void>

    await table.fill("column1")
     
    -
  • Extracts a specific number of characters, starting from the left.

    Parameters

    • column: string

      The name of the column storing the strings

    • numberOfCharacters: number

      The number of characters, starting from the left

    Returns Promise<void>

    // Strings in column1 will be replaced by the first two characters of each string.
    await table.left("column1", 2)
    -
  • Formats strings to lowercase.

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns to be updated.

    Returns Promise<void>

    await table.lower("column1")
     
    @@ -1363,7 +1364,7 @@
    await table.lower(["column1", "column2"])
     
    -
  • Replaces specified strings in the selected columns

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns where string replacements will occur.

    • strings: {
          [key: string]: string;
      }

      An object mapping old strings to new strings.

      • [key: string]: string
    • options: {
          entireString?: boolean;
          regex?: boolean;
      } = {}

      An optional object with configuration options:

      @@ -1381,19 +1382,19 @@
      // Replaces using a regular expression. Any sequence of one or more digits would be replaced by a hyphen.
      await table.replace("column1", {"\d+": "-" }, {regex: true})
      -
  • Replaces null values in the selected columns.

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns where string replacements will occur.

    • value:
          | string
          | number
          | boolean
          | Date

      The value to replace the null values.

    Returns Promise<void>

    // Replace null values by 0.
    await table.replaceNulls("column1", 0)
    -
  • Extracts a specific number of characters, starting from the right.

    Parameters

    • column: string

      The name of the column storing the strings

    • numberOfCharacters: number

      The number of characters, starting from the right

    Returns Promise<void>

    // Strings in column1 will be replaced by the last two characters of each string.
    await table.right("column1", 2)
    -
  • Rounds numeric values in specified columns.

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns containing numeric values to be rounded.

    • options: {
          decimals?: number;
          method?: "round" | "ceiling" | "floor";
      } = {}

      An optional object with configuration options:

      • Optionaldecimals?: number

        The number of decimal places to round to. Defaults to 0.

        @@ -1407,14 +1408,14 @@
        // Rounds column1's values with a specific method. Available methods are "round", "floor" and "ceiling".
        await table.round("column1", { method: "floor" })
        -
  • Splits strings along a separator and replaces the values with a substring at a specified index (starting at 0). If the index is outside the bounds of the list, return an empty string.

    +
  • Splits strings along a separator and replaces the values with a substring at a specified index (starting at 0). If the index is outside the bounds of the list, return an empty string.

    Parameters

    • column: string

      The name of the column storing the strings

    • separator: string

      The substring to use as a separator

    • index: number

      The index of the substring to replace values

    Returns Promise<void>

    // Splits on commas and replaces values with the second substring.
    await table.splitExtract("column1", ",", 1)
    -
  • Trims specified characters from the beginning, end, or both sides of string values.

    Parameters

    • columns: string | string[]

      The column or columns to trim.

    • options: {
          character?: string;
          method?: "leftTrim" | "rightTrim" | "trim";
      } = {}

      An optional object with configuration options:

      • Optionalcharacter?: string

        The string to trim. Defaults to whitespace.

        @@ -1425,23 +1426,23 @@
        // Trims values in column2, columns3, and column4
        await table.trim(["column2", "column3", "column4"])
        -
  • Updates values in a specified column with a SQL expression.

    Parameters

    • column: string

      The name of the column to be updated.

    • definition: string

      The SQL expression to set the new values in the column.

    Returns Promise<void>

    await table.updateColumn("column1", `LEFT(column2)`)
     
    -
  • Updates data using a JavaScript function. The function takes the existing rows as an array of objects and must return them modified as an array of objects. This method provides a flexible way to update data, but it's slow. This won't work with tables containing geometries.

    +
  • Updates data using a JavaScript function. The function takes the existing rows as an array of objects and must return them modified as an array of objects. This method provides a flexible way to update data, but it's slow. This won't work with tables containing geometries.

    Parameters

    • dataModifier: ((rows: {
          [key: string]:
              | number
              | string
              | Date
              | boolean
              | null;
      }[]) => Promise<{
          [key: string]:
              | number
              | string
              | Date
              | boolean
              | null;
      }[]>) | ((rows: {
          [key: string]:
              | number
              | string
              | Date
              | boolean
              | null;
      }[]) => {
          [key: string]:
              | number
              | string
              | Date
              | boolean
              | null;
      }[])

      A function that takes the existing rows and returns modified rows using JavaScript logic. The original rows are objects in an array and the modified rows must be returned as an array of objects too.

    Returns Promise<void>

    // Adds one to the values from column1. If the values are not numbers, they are replaced by null.
    await table.updateWithJS((rows) => {
    const modifiedRows = rows.map(d => ({
    ...d,
    column1: typeof d.column1 === "number" ? d.column1 + 1 : null
    }))
    return modifiedRows
    })
    -
  • Formats strings to uppercase.

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns to be updated.

    Returns Promise<void>

    await table.upper("tableA", "column1")

    @example Multiple columns
    await table.upper(["column1", "column2"])
    -

Other

Other

  • Caches the results of computations in ./.sda-cache which you probably want to add to your .gitignore.

    Parameters

    • run: (() => Promise<void>)

      A function wrapping the computations.

        • (): Promise<void>
        • Returns Promise<void>

    • options: {
          ttl?: number;
      } = {}

      An optional object with configuration options:

      • Optionalttl?: number

        If the data in cache is older than the ttl (in seconds), the computations will be run. By default, there is no ttl.

        @@ -1457,7 +1458,7 @@
  • Returns a new table with the same structure and data as this table. The data can be optionally filtered. This can be very slow with big tables.

    +
  • Returns a new table with the same structure and data as this table. The data can be optionally filtered. This can be very slow with big tables.

    Parameters

    • options: {
          condition?: string;
          outputTable?: string;
      } = {}

      An optional object with configuration options:

      • Optionalcondition?: string

        A SQL WHERE clause condition to filter the data. Defaults to no condition.

      • OptionaloutputTable?: string

        The name in the DB of the new table that will be created as a clone.

        @@ -1470,43 +1471,43 @@
        // Creating tableB as a clone of tableA. Only rows with values greater than 10 in column1 are cloned.
        const tableB = await tableA.cloneTable({ condition: `column1 > 10` })
        -
  • Returns descriptive information about the columns, including details like data types, number of null and distinct values. Best to look at with console.table.

    +

    Returns Promise<string[]>

  • Returns descriptive information about the columns, including details like data types, number of null and distinct values. Best to look at with console.table.

    Returns Promise<{
        [key: string]: unknown;
    }[]>

    const description = await table.getDescription()
     
    -
  • Returns the number of values (number of columns * number of rows) in a table.

    Returns Promise<number>

    const nbValues = await table.getNbValues()
     
    -
  • Returns the schema (column names and their data types).

    Returns Promise<{
        [key: string]: string | null;
    }[]>

    const schema = await table.getSchema()
     
    -
  • Returns the data types of columns.

    Returns Promise<{
        [key: string]: string;
    }>

    const dataTypes = await table.getTypes()
     
    -
  • Returns TRUE if the table has the column and FALSE otherwise.

    Parameters

    • column: string

    Returns Promise<boolean>

    const bool = await table.hasColum("name")
     
    -
  • Logs descriptive information about the columns, including details like data types, number of null and distinct values. It calls getDescription.

    +
  • Logs descriptive information about the columns, including details like data types, number of null and distinct values. It calls getDescription.

    Returns Promise<void>

    await table.logDescription()
     
    -
  • Logs a specified number of rows. Default is 10 rows.

    Parameters

    • OptionalnbRowsToLog: number

      The number of rows to log when debugging. Defaults to 10 or the value set in the SimpleWebDB instance.

    Returns Promise<void>

    // Logs first 10 rows
    await table.logTable();
    @@ -1514,14 +1515,14 @@
    // Logs first 100 rows
    await table.logTable(100);
    -
  • Set the types in the table.

    Parameters

    • types: {
          [key: string]:
              | "integer"
              | "float"
              | "number"
              | "string"
              | "date"
              | "time"
              | "datetime"
              | "datetimeTz"
              | "bigint"
              | "double"
              | "varchar"
              | "timestamp"
              | "timestamp with time zone"
              | "boolean"
              | "geometry";
      }

      An object specifying the columns and their data types (JavaScript or SQL).

      • [key: string]:
            | "integer"
            | "float"
            | "number"
            | "string"
            | "date"
            | "time"
            | "datetime"
            | "datetimeTz"
            | "bigint"
            | "double"
            | "varchar"
            | "timestamp"
            | "timestamp with time zone"
            | "boolean"
            | "geometry"

    Returns Promise<void>

     await table.setTypes({
    name: "string",
    salary: "integer",
    raise: "float",
    })
    -
+
diff --git a/docs/classes/SimpleWebDB.html b/docs/classes/SimpleWebDB.html index 4f20bdc5..ac1c4d6c 100644 --- a/docs/classes/SimpleWebDB.html +++ b/docs/classes/SimpleWebDB.html @@ -1,4 +1,4 @@ -SimpleWebDB | Simple-data-analysis - v3.6.2

SimpleWebDB is a class that provides a simplified interface for working with DuckDB, a high-performance in-memory analytical database. This class is meant to be used in a web browser. For NodeJS and similar runtimes, use SimpleDB.

+SimpleWebDB | Simple-data-analysis - v3.6.3

SimpleWebDB is a class that provides a simplified interface for working with DuckDB, a high-performance in-memory analytical database. This class is meant to be used in a web browser. For NodeJS and similar runtimes, use SimpleDB.

Here's how to instantiate a SimpleWebDB instance and then a SimpleWebTable.

// Instantiating the database.
const sdb = new SimpleWebDB()

// Creating a new table.
const employees = sdb.newTable("employees")

// You can now invoke methods on the table.
await employees.loadData("./employees.csv")
await employees.logTable()

// Removing the table.
await employees.removeTable()

// Removing the DB to free up memory.
await sdb.done()
@@ -6,7 +6,7 @@
// Creating a database with options. Debug information will be logged each time a method is invoked. The first 20 rows of tables will be logged (default is 10).
const sdb = new SimpleWebDB({ debug: true, nbRowsToLog: 20 })
-

Hierarchy (view full)

Properties

Hierarchy (view full)

Properties

Internal

Properties

bigIntToInt: undefined | boolean

A flag for SimpleDB. Default is true. When data is retrieved from the database as an array of objects, BIGINT values are automatically converted to integers, which are easier to work with in JavaScript. If you want actual bigint values, set this option to false.

-
cacheSourcesUsed: string[]

An object keeping track of the data used in cache.

-
connection: AsyncDuckDBConnection | Connection

A connection to a DuckDB database.

-
db: AsyncDuckDB | Database

A DuckDB database.

-
debug: boolean

A flag indicating whether debugging information should be logged. Defaults to false.

-
defaultTableName: boolean

A flag to know if the name of the table has been attributed by default.

-
durationStart: undefined | number

A timestamp used to track the total duration logged in done().

-
nbCharactersToLog: undefined | number

The number of characters to log for text cells. By default, the whole text is logged.

-
nbRowsToLog: number

The number of rows to log. Defaults to 10.

-
runQuery: ((query: string, connection: AsyncDuckDBConnection | Connection, returnDataFromQuery: boolean, options: {
    bigIntToInt?: boolean;
    debug: boolean;
    method: null | string;
    parameters: null | {
        [key: string]: unknown;
    };
}) => Promise<null | {
    [key: string]:
        | number
        | string
        | Date
        | boolean
        | null;
}[]>)

For internal use only. If you want to run a SQL query, use the customQuery method.

-
tableIncrement: number

A number used when creating new tables.

-
worker: null | Worker

A worker to make DuckDB WASM work.

-

DB methods

  • Executes a custom SQL query, providing flexibility for advanced users.

    +
cacheSourcesUsed: string[]

An object keeping track of the data used in cache.

+
connection: AsyncDuckDBConnection | Connection

A connection to a DuckDB database.

+
db: AsyncDuckDB | Database

A DuckDB database.

+
debug: boolean

A flag indicating whether debugging information should be logged. Defaults to false.

+
defaultTableName: boolean

A flag to know if the name of the table has been attributed by default.

+
durationStart: undefined | number

A timestamp used to track the total duration logged in done().

+
nbCharactersToLog: undefined | number

The number of characters to log for text cells. By default, the whole text is logged.

+
nbRowsToLog: number

The number of rows to log. Defaults to 10.

+
runQuery: ((query: string, connection: AsyncDuckDBConnection | Connection, returnDataFromQuery: boolean, options: {
    bigIntToInt?: boolean;
    debug: boolean;
    method: null | string;
    parameters: null | {
        [key: string]: unknown;
    };
}) => Promise<null | {
    [key: string]:
        | number
        | string
        | Date
        | boolean
        | null;
}[]>)

For internal use only. If you want to run a SQL query, use the customQuery method.

+
tableIncrement: number

A number used when creating new tables.

+
worker: null | Worker

A worker to make DuckDB WASM work.

+

DB methods

  • Executes a custom SQL query, providing flexibility for advanced users.

    Parameters

    • query: string

      The custom SQL query to be executed.

    • options: {
          returnDataFrom?: "query" | "none";
          table?: string;
      } = {}

      An optional object with configuration options:

      • OptionalreturnDataFrom?: "query" | "none"

        Specifies whether to return data from the "query" or not. Defaults to "none".

        @@ -46,24 +46,24 @@

    Returns Promise<null | {
        [key: string]:
            | string
            | number
            | boolean
            | Date
            | null;
    }[]>

    // You can use the returnDataFrom option to retrieve the data from the query, if needed.
    const data = await sdb.customQuery("SELECT * FROM employees WHERE Job = 'Clerk'", { returnDataFrom: "query" })
    -
  • Frees up memory. Closes the connection to the database and terminates associated resources.

    +
  • Frees up memory. Closes the connection to the database and terminates associated resources.

    Returns Promise<void>

    await sdb.done();
     
    -
  • Returns the DuckDB extensions.

    +
  • Returns the DuckDB extensions.

    const extensions = await sdb.getExtensions()
     
    -

    Returns Promise<{
        [key: string]:
            | string
            | number
            | boolean
            | Date
            | null;
    }[]>

  • Returns the list of tables.

    +

    Returns Promise<{
        [key: string]:
            | string
            | number
            | boolean
            | Date
            | null;
    }[]>

  • Returns the list of tables.

    Returns Promise<string[]>

    const tables = await sdb.getTables()
     
    -
  • Returns true if a specified table exists and false if not.

    +
  • Returns true if a specified table exists and false if not.

    Parameters

    • table: string

      The name of the table to check for existence.

    Returns Promise<boolean>

    const hasEmployees = await sdb.hasTable("employees")
     
    -
  • Creates a table in the DB.

    Parameters

    • Optionalname: string

      The name of the new table.

    • Optionalprojections: {
          [key: string]: string;
      }

      The projections of the geospatial data, if any.

      • [key: string]: string

    Returns SimpleWebTable

    // This returns a new SimpleWebTable
    const employees = sdb.newTable() @@ -72,7 +72,7 @@
    // By default, tables will be named table1, table2, etc.
    // But you can also give them specific names.
    const employees = sdb.newTable("employees")
    -
  • Remove a table or multiple tables from the database. Invoking methods on the tables will throw and error.

    +
  • Remove a table or multiple tables from the database. Invoking methods on the tables will throw and error.

    Parameters

    Returns Promise<void>

    await table.removeTables(tableA)
     
    @@ -80,5 +80,5 @@
    await table.removeTables([tableA, tableB])
     
    -

Internal

+

Internal

diff --git a/docs/classes/SimpleWebTable.html b/docs/classes/SimpleWebTable.html index 5c439ad7..94f6fd94 100644 --- a/docs/classes/SimpleWebTable.html +++ b/docs/classes/SimpleWebTable.html @@ -1,11 +1,11 @@ -SimpleWebTable | Simple-data-analysis - v3.6.2

SimpleWebTable is a class representing a table in a SimpleWebDB. It can handle tabular and geospatial data. To create one, it's best to instantiate a SimpleWebDB first.

+SimpleWebTable | Simple-data-analysis - v3.6.3

SimpleWebTable is a class representing a table in a SimpleWebDB. It can handle tabular and geospatial data. To create one, it's best to instantiate a SimpleWebDB first.

// Creating a database first.
const sdb = new SimpleWebDB()

// Making a new table. This returns a SimpleWebTable.
const table = sdb.newTable()

// You can now invoke methods on the table.
const url = ".../some-file.csv"
await table.fetchData(url)
await table.logTable()

// Removing the DB to free up memory.
await sdb.done()
const boundaries = sdb.newTable()
// To load geospatial data, use .fetchGeoData instead of .fetchData
const url = ".../some-file.geojson"
await boundaries.fetchGeoData(url)
-

Hierarchy (view full)

Properties

Hierarchy (view full)

Properties

Properties

bigIntToInt: undefined | boolean

A flag for SimpleDB. Default is true. When data is retrieved from the database as an array of objects, BIGINT values are automatically converted to integers, which are easier to work with in JavaScript. If you want actual bigint values, set this option to false.

-
connection: AsyncDuckDBConnection | Connection

A connection to a DuckDB database.

-
db: AsyncDuckDB | Database

A DuckDB database.

-
debug: boolean

A flag indicating whether debugging information should be logged. Defaults to false.

-
defaultTableName: boolean

A flag to know if the name of the table has been attributed by default.

-
name: string

Name of the table in the database.

-
nbCharactersToLog: undefined | number

The number of characters to log for text cells. By default, the whole text is logged.

-
nbRowsToLog: number

The number of rows to log. Defaults to 10.

-
projections: {
    [key: string]: string;
}

The projections of the geospatial data, if any.

-
runQuery: ((query: string, connection: AsyncDuckDBConnection | Connection, returnDataFromQuery: boolean, options: {
    bigIntToInt?: boolean;
    debug: boolean;
    method: null | string;
    parameters: null | {
        [key: string]: unknown;
    };
}) => Promise<null | {
    [key: string]:
        | number
        | string
        | Date
        | boolean
        | null;
}[]>)

For internal use only. If you want to run a SQL query, use the customQuery method.

-

The SimpleWebDB that created this table.

-
tableIncrement: number

A number used when creating new tables.

-
worker: null | Worker

A worker to make DuckDB WASM work.

-

Analyzing data

  • Assigns bins for specified column values based on an interval size.

    +
connection: AsyncDuckDBConnection | Connection

A connection to a DuckDB database.

+
db: AsyncDuckDB | Database

A DuckDB database.

+
debug: boolean

A flag indicating whether debugging information should be logged. Defaults to false.

+
defaultTableName: boolean

A flag to know if the name of the table has been attributed by default.

+
name: string

Name of the table in the database.

+
nbCharactersToLog: undefined | number

The number of characters to log for text cells. By default, the whole text is logged.

+
nbRowsToLog: number

The number of rows to log. Defaults to 10.

+
projections: {
    [key: string]: string;
}

The projections of the geospatial data, if any.

+
runQuery: ((query: string, connection: AsyncDuckDBConnection | Connection, returnDataFromQuery: boolean, options: {
    bigIntToInt?: boolean;
    debug: boolean;
    method: null | string;
    parameters: null | {
        [key: string]: unknown;
    };
}) => Promise<null | {
    [key: string]:
        | number
        | string
        | Date
        | boolean
        | null;
}[]>)

For internal use only. If you want to run a SQL query, use the customQuery method.

+

The SimpleWebDB that created this table.

+
tableIncrement: number

A number used when creating new tables.

+
worker: null | Worker

A worker to make DuckDB WASM work.

+

Analyzing data

  • Assigns bins for specified column values based on an interval size.

    Parameters

    • values: string

      The column containing values from which bins will be computed.

    • interval: number

      The interval size for binning the values.

    • newColumn: string

      The name of the new column where the bins will be stored.

      @@ -155,7 +155,7 @@
  • Calculates correlations between columns.

    If no x and y columns are specified, the method computes the correlations of all numeric columns combinations. It's important to note that correlation is symmetrical: the correlation of x over y is the same as y over x.

    Parameters

    • options: {
          categories?: string | string[];
          decimals?: number;
          outputTable?: string | boolean;
          x?: string;
          y?: string;
      } = {}

      An optional object with configuration options:

      • Optionalcategories?: string | string[]

        The column or columns that define categories. Correlation calculations will be run for each category.

        @@ -178,7 +178,7 @@
        // Same but results are stored in tableB.
        const tableB = await table.correlations({ outputTable: "tableB" })
        -
  • Performs linear regression analysis. The results include the slope, the y-intercept the R-squared.

    If no x and y columns are specified, the method computes the linear regression analysis of all numeric columns permutations. It's important to note that linear regression analysis is asymmetrical: the linear regression of x over y is not the same as y over x.

    Parameters

    • options: {
          categories?: string | string[];
          decimals?: number;
          outputTable?: string | true;
          x?: string;
          y?: string;
      } = {}

      An optional object with configuration options:

      • Optionalcategories?: string | string[]

        The column or columns that define categories. Correlation calculations will be run for each category.

        @@ -200,7 +200,7 @@
        // Same but stores the results in tableB.
        const tableB = await table.linearRegressions({ outputTable: "tableB" })
        -
  • Normalizes the values in a column using min-max normalization.

    +
  • Normalizes the values in a column using min-max normalization.

    Parameters

    • column: string

      The name of the column in which values will be normalized.

    • newColumn: string

      The name of the new column where normalized values will be stored.

    • options: {
          categories?: string | string[];
          decimals?: number;
      } = {}

      An optional object with configuration options:

      @@ -215,7 +215,7 @@
  • Identifies outliers using the Interquartile Range (IQR) method.

    +
  • Identifies outliers using the Interquartile Range (IQR) method.

    Parameters

    • column: string

      The name of the column in which outliers will be identified.

    • newColumn: string

      The name of the new column where the bins will be stored.

    • options: {
          categories?: string | string[];
      } = {}

      An optional object with configuration options:

      @@ -226,7 +226,7 @@
  • Computes proportions within a row for specified columns.

    +
  • Computes proportions within a row for specified columns.

    For example, let's say this is tableA.

    @@ -356,7 +356,7 @@
    @@ -1087,26 +1087,26 @@
    -
  • Removes one or more columns from this table.

    Parameters

    • columns: string | string[]

      The name or an array of names of the columns to be removed.

    Returns Promise<void>

    await table.removeColumns(["column1", "column2"])
     
    -
  • Remove the table from the database. Invoking methods on this table will throw and error.

    +
  • Remove the table from the database. Invoking methods on this table will throw and error.

    Returns Promise<void>

    await table.removeTable()
     
    -
  • Renames columns in the table.

    Parameters

    • names: {
          [key: string]: string;
      }

      An object mapping old column names to new column names.

      • [key: string]: string

    Returns Promise<void>

    // Renaming "How old?" to "age" and "Man or woman?" to "sex".
    await table.renameColumns({ "How old?" : "age", "Man or woman?": "sex" })
    -
  • Selects specific columns in the table and removes the others.

    +
  • Selects specific columns in the table and removes the others.

    Parameters

    • columns: string | string[]

      Either a string (one column) or an array of strings (multiple columns) representing the columns to be selected.

    Returns Promise<void>

    // Selecting only the columns firstName and lastName. All other columns in the table will be removed.
    await table.selectColumns([ "firstName", "lastName" ])
    -
  • Sorts the rows based on specified column(s) and order(s).

    Parameters

    • order: {
          [key: string]: "asc" | "desc";
      }

      An object mapping column names to the sorting order: "asc" for ascending or "desc" for descending.

      • [key: string]: "asc" | "desc"
    • options: {
          lang?: {
              [key: string]: string;
          };
      } = {}

      An optional object with configuration options:

      • Optionallang?: {
            [key: string]: string;
        }

        An object mapping column names to language codes. See DuckDB Collations documentation for more: https://duckdb.org/docs/sql/expressions/collations.

        @@ -1119,7 +1119,7 @@
        // Taking French accent into account in column1
        await table.sort({ column1: "asc", column2: "desc" }, { lang: { column1: "fr" }})
        -
  • Restructures this table by unstacking values.

    As an example, let's use this table. It shows the number of employees per year in different departments.

    @@ -1193,7 +1193,7 @@
    -

Selecting or filtering data

  • Filters rows from this table based on SQL conditions. Note that it's often faster to use the removeRows method.

    +

Selecting or filtering data

  • Filters rows from this table based on SQL conditions. Note that it's often faster to use the removeRows method.

    Parameters

    • conditions: string

      The filtering conditions specified as a SQL WHERE clause.

    Returns Promise<void>

    // Keeps only rows where the fruit is not an apple.
    await table.filter(`fruit != 'apple'`)
    @@ -1201,23 +1201,23 @@
    await table.filter(`price > 100 AND quantity > 0`)
    await table.filter(`category = 'Electronics' OR category = 'Appliances'`)
    await table.filter(`lastPurchaseDate >= '2023-01-01'`)
    -
  • Keeps rows with specific values in specific columns.

    Parameters

    • columnsAndValues: {
          [key: string]: unknown[];
      }

      An object with the columns (keys) and the values to be kept (values as arrays)

      • [key: string]: unknown[]

    Returns Promise<void>

    // Keeps only rows where the job is 'accountant' or 'developer' and where the city is 'Montreal'.
    await table.keep({ job: ["accountant", "developer"], city: ["Montreal"] })
    -
  • Remove rows with specific values in specific columns.

    Parameters

    • columnsAndValues: {
          [key: string]: unknown[];
      }

      An object with the columns (keys) and the values to be removed (values as arrays)

      • [key: string]: unknown[]

    Returns Promise<void>

    // Remove rows where the job is 'accountant' or 'developer' and where the city is 'Montreal'.
    await table.remove({ job: ["accountant", "developer"], city: ["Montreal"] })
    -
  • Removes duplicate rows from this table, keeping unique rows. Note that SQL does not guarantee any specific order when using DISTINCT. So the data might be returned in a different order than the original.

    +
  • Removes duplicate rows from this table, keeping unique rows. Note that SQL does not guarantee any specific order when using DISTINCT. So the data might be returned in a different order than the original.

    Parameters

    • options: {
          on?: string | string[];
      } = {}

      An optional object with configuration options:

      • Optionalon?: string | string[]

        A column or multiple columns to consider to remove duplicates. The other columns in the table will not be considered to exclude duplicates.

    Returns Promise<void>

    await table.removeDuplicates("tableA")
     
    -
  • Removes rows with missing values from this table. By default, missing values are NULL (as an SQL value), but also "NULL", "null", "NaN" and "undefined" that might have been converted to strings before being loaded into the table. Empty strings "" are also considered missing values.

    +
  • Removes rows with missing values from this table. By default, missing values are NULL (as an SQL value), but also "NULL", "null", "NaN" and "undefined" that might have been converted to strings before being loaded into the table. Empty strings "" are also considered missing values.

    Parameters

    • options: {
          columns?: string | string[];
          invert?: boolean;
          missingValues?: (string | number)[];
      } = {}

      An optional object with configuration options:

      • Optionalcolumns?: string | string[]

        Either a string or an array of strings specifying the columns to consider for missing values. By default, all columns are considered.

      • Optionalinvert?: boolean

        A boolean indicating whether to invert the condition, keeping only rows with missing values. Defaults to false.

        @@ -1228,12 +1228,12 @@
        // Removes rows with missing values in specific columns.
        await table.removeMissing({ columns: ["firstName", "lastName"] })
        -
  • Removes rows from this table based on SQL conditions.

    Parameters

    • conditions: string

      The filtering conditions specified as a SQL WHERE clause.

    Returns Promise<void>

    // Removes rows where the fruit is an apple.
    await table.removeRows(`fruit = 'apple'`)
    -
  • Selects random rows from the table and removes the others. You can optionally specify a seed to ensure the same random rows are selected each time.

    +
  • Selects random rows from the table and removes the others. You can optionally specify a seed to ensure the same random rows are selected each time.

    Parameters

    • quantity: string | number

      The number of rows (1000 for example) or a string ("10%" for example) specifying the sampling size.

    • options: {
          seed?: number;
      } = {}

      An optional object with configuration options:

      • Optionalseed?: number

        A number specifying the seed for repeatable sampling. For example, setting it to 1 will ensure random rows will be the same each time you run the method.

        @@ -1246,7 +1246,7 @@
        // Selects always the same random rows
        await table.sample("10%", { seed: 1 })
        -
  • Selects n rows from this table. An offset and outputTable options are available.

    Parameters

    • count: string | number

      The number of rows.

    • options: {
          offset?: number;
          outputTable?: string | boolean;
      } = {}

      An optional object with configuration options:

      • Optionaloffset?: number

        The number of rows to skip before selecting. Defaults to 0.

        @@ -1263,12 +1263,12 @@
        // Selects 100 rows and stores them in a new table.
        const tableB = await tableA.selectRows(100, { outputTable: "tableB" })
        -
  • Skips the first X rows.

    Parameters

    • nbRowsToSkip: number

      The number of rows to skip.

    Returns Promise<void>

    // Skips the first 10 rows.
    await table.skip(10)
    -

Updating data

  • Concatenates values from specified columns into a new column.

    +

Updating data

  • Concatenates values from specified columns into a new column.

    Parameters

    • columns: string[]

      An array of column names from which values will be concatenated.

    • newColumn: string

      The name of the new column to store the concatenated values.

    • options: {
          separator?: string;
      } = {}

      An optional object with configuration options:

      @@ -1279,18 +1279,18 @@
      // Same thing, but the values will be separated by a dash
      await table.concatenate(["column1", "column2"], "column3", { separator: "-" })
      -
  • Fills cells containing NULL values. If a cell is empty, it's filled with the previous row's value.

    +
  • Fills cells containing NULL values. If a cell is empty, it's filled with the previous row's value.

    Parameters

    • columns: string | string[]

      The columns to fill.

    Returns Promise<void>

    await table.fill("column1")
     
    -
  • Extracts a specific number of characters, starting from the left.

    +
  • Extracts a specific number of characters, starting from the left.

    Parameters

    • column: string

      The name of the column storing the strings

    • numberOfCharacters: number

      The number of characters, starting from the left

    Returns Promise<void>

    // Strings in column1 will be replaced by the first two characters of each string.
    await table.left("column1", 2)
    -
  • Formats strings to lowercase.

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns to be updated.

    Returns Promise<void>

    await table.lower("column1")
     
    @@ -1298,7 +1298,7 @@
    await table.lower(["column1", "column2"])
     
    -
  • Replaces specified strings in the selected columns

    +
  • Replaces specified strings in the selected columns

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns where string replacements will occur.

    • strings: {
          [key: string]: string;
      }

      An object mapping old strings to new strings.

      • [key: string]: string
    • options: {
          entireString?: boolean;
          regex?: boolean;
      } = {}

      An optional object with configuration options:

      @@ -1316,19 +1316,19 @@
      // Replaces using a regular expression. Any sequence of one or more digits would be replaced by a hyphen.
      await table.replace("column1", {"\d+": "-" }, {regex: true})
      -
  • Replaces null values in the selected columns.

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns where string replacements will occur.

    • value:
          | string
          | number
          | boolean
          | Date

      The value to replace the null values.

    Returns Promise<void>

    // Replace null values by 0.
    await table.replaceNulls("column1", 0)
    -
  • Extracts a specific number of characters, starting from the right.

    +
  • Extracts a specific number of characters, starting from the right.

    Parameters

    • column: string

      The name of the column storing the strings

    • numberOfCharacters: number

      The number of characters, starting from the right

    Returns Promise<void>

    // Strings in column1 will be replaced by the last two characters of each string.
    await table.right("column1", 2)
    -
  • Rounds numeric values in specified columns.

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns containing numeric values to be rounded.

    • options: {
          decimals?: number;
          method?: "round" | "ceiling" | "floor";
      } = {}

      An optional object with configuration options:

      • Optionaldecimals?: number

        The number of decimal places to round to. Defaults to 0.

        @@ -1342,14 +1342,14 @@
        // Rounds column1's values with a specific method. Available methods are "round", "floor" and "ceiling".
        await table.round("column1", { method: "floor" })
        -
  • Splits strings along a separator and replaces the values with a substring at a specified index (starting at 0). If the index is outside the bounds of the list, return an empty string.

    +
  • Splits strings along a separator and replaces the values with a substring at a specified index (starting at 0). If the index is outside the bounds of the list, return an empty string.

    Parameters

    • column: string

      The name of the column storing the strings

    • separator: string

      The substring to use as a separator

    • index: number

      The index of the substring to replace values

    Returns Promise<void>

    // Splits on commas and replaces values with the second substring.
    await table.splitExtract("column1", ",", 1)
    -
  • Trims specified characters from the beginning, end, or both sides of string values.

    +
  • Trims specified characters from the beginning, end, or both sides of string values.

    Parameters

    • columns: string | string[]

      The column or columns to trim.

    • options: {
          character?: string;
          method?: "leftTrim" | "rightTrim" | "trim";
      } = {}

      An optional object with configuration options:

      • Optionalcharacter?: string

        The string to trim. Defaults to whitespace.

        @@ -1360,23 +1360,23 @@
        // Trims values in column2, columns3, and column4
        await table.trim(["column2", "column3", "column4"])
        -
  • Updates values in a specified column with a SQL expression.

    +
  • Updates values in a specified column with a SQL expression.

    Parameters

    • column: string

      The name of the column to be updated.

    • definition: string

      The SQL expression to set the new values in the column.

    Returns Promise<void>

    await table.updateColumn("column1", `LEFT(column2)`)
     
    -
  • Updates data using a JavaScript function. The function takes the existing rows as an array of objects and must return them modified as an array of objects. This method provides a flexible way to update data, but it's slow. This won't work with tables containing geometries.

    +
  • Updates data using a JavaScript function. The function takes the existing rows as an array of objects and must return them modified as an array of objects. This method provides a flexible way to update data, but it's slow. This won't work with tables containing geometries.

    Parameters

    • dataModifier: ((rows: {
          [key: string]:
              | number
              | string
              | Date
              | boolean
              | null;
      }[]) => Promise<{
          [key: string]:
              | number
              | string
              | Date
              | boolean
              | null;
      }[]>) | ((rows: {
          [key: string]:
              | number
              | string
              | Date
              | boolean
              | null;
      }[]) => {
          [key: string]:
              | number
              | string
              | Date
              | boolean
              | null;
      }[])

      A function that takes the existing rows and returns modified rows using JavaScript logic. The original rows are objects in an array and the modified rows must be returned as an array of objects too.

    Returns Promise<void>

    // Adds one to the values from column1. If the values are not numbers, they are replaced by null.
    await table.updateWithJS((rows) => {
    const modifiedRows = rows.map(d => ({
    ...d,
    column1: typeof d.column1 === "number" ? d.column1 + 1 : null
    }))
    return modifiedRows
    })
    -
  • Formats strings to uppercase.

    Parameters

    • columns: string | string[]

      Either a string or an array of strings specifying the columns to be updated.

    Returns Promise<void>

    await table.upper("tableA", "column1")

    @example Multiple columns
    await table.upper(["column1", "column2"])
    -

Other

  • Returns a new table with the same structure and data as this table. The data can be optionally filtered. This can be very slow with big tables.

    +

Other

  • Returns a new table with the same structure and data as this table. The data can be optionally filtered. This can be very slow with big tables.

    Parameters

    • options: {
          condition?: string;
          outputTable?: string;
      } = {}

      An optional object with configuration options:

      • Optionalcondition?: string

        A SQL WHERE clause condition to filter the data. Defaults to no condition.

      • OptionaloutputTable?: string

        The name in the DB of the new table that will be created as a clone.

        @@ -1389,43 +1389,43 @@
        // Creating tableB as a clone of tableA. Only rows with values greater than 10 in column1 are cloned.
        const tableB = await tableA.cloneTable({ condition: `column1 > 10` })
        -
  • Return the list of column names.

    const columns = await table.getColumns()
     
    -

    Returns Promise<string[]>

  • Returns descriptive information about the columns, including details like data types, number of null and distinct values. Best to look at with console.table.

    +

    Returns Promise<string[]>

  • Returns descriptive information about the columns, including details like data types, number of null and distinct values. Best to look at with console.table.

    Returns Promise<{
        [key: string]: unknown;
    }[]>

    const description = await table.getDescription()
     
    -
  • Returns the number of columns.

    Returns Promise<number>

    const nbColumns = await table.getNbColumns()
     
    -
  • Returns the number of rows in a table.

    Returns Promise<number>

    const nbRows = await table.getNbRows()
     
    -
  • Returns the number of values (number of columns * number of rows) in a table.

    +
  • Returns the number of values (number of columns * number of rows) in a table.

    Returns Promise<number>

    const nbValues = await table.getNbValues()
     
    -
  • Returns the schema (column names and their data types).

    +
  • Returns the schema (column names and their data types).

    Returns Promise<{
        [key: string]: string | null;
    }[]>

    const schema = await table.getSchema()
     
    -
  • Returns the data types of columns.

    Returns Promise<{
        [key: string]: string;
    }>

    const dataTypes = await table.getTypes()
     
    -
  • Returns TRUE if the table has the column and FALSE otherwise.

    Parameters

    • column: string

    Returns Promise<boolean>

    const bool = await table.hasColum("name")
     
    -
  • Logs descriptive information about the columns, including details like data types, number of null and distinct values. It calls getDescription.

    +
  • Logs descriptive information about the columns, including details like data types, number of null and distinct values. It calls getDescription.

    Returns Promise<void>

    await table.logDescription()
     
    -
  • Logs a specified number of rows. Default is 10 rows.

    Parameters

    • OptionalnbRowsToLog: number

      The number of rows to log when debugging. Defaults to 10 or the value set in the SimpleWebDB instance.

    Returns Promise<void>

    // Logs first 10 rows
    await table.logTable();
    @@ -1433,14 +1433,14 @@
    // Logs first 100 rows
    await table.logTable(100);
    -
  • Rename the table.

    Parameters

    • name: string

      New name for the table

    Returns Promise<void>

    await table.renameTable("newName")
     
    -
  • Set the types in the table.

    Parameters

    • types: {
          [key: string]:
              | "integer"
              | "float"
              | "number"
              | "string"
              | "date"
              | "time"
              | "datetime"
              | "datetimeTz"
              | "bigint"
              | "double"
              | "varchar"
              | "timestamp"
              | "timestamp with time zone"
              | "boolean"
              | "geometry";
      }

      An object specifying the columns and their data types (JavaScript or SQL).

      • [key: string]:
            | "integer"
            | "float"
            | "number"
            | "string"
            | "date"
            | "time"
            | "datetime"
            | "datetimeTz"
            | "bigint"
            | "double"
            | "varchar"
            | "timestamp"
            | "timestamp with time zone"
            | "boolean"
            | "geometry"

    Returns Promise<void>

     await table.setTypes({
    name: "string",
    salary: "integer",
    raise: "float",
    })
    -
+
diff --git a/docs/hierarchy.html b/docs/hierarchy.html index c993882a..917a5560 100644 --- a/docs/hierarchy.html +++ b/docs/hierarchy.html @@ -1 +1 @@ -Simple-data-analysis - v3.6.2

Simple-data-analysis - v3.6.2

Class Hierarchy

+Simple-data-analysis - v3.6.3

Simple-data-analysis - v3.6.3

Class Hierarchy

diff --git a/docs/index.html b/docs/index.html index 655a997f..4b42219b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,4 +1,4 @@ -Simple-data-analysis - v3.6.2

Simple-data-analysis - v3.6.2

Simple data analysis (SDA)

SDA is an easy-to-use and high-performance JavaScript library for data analysis. You can use it with tabular and geospatial data.

+Simple-data-analysis - v3.6.3

Simple-data-analysis - v3.6.3

Simple data analysis (SDA)

SDA is an easy-to-use and high-performance JavaScript library for data analysis. You can use it with tabular and geospatial data.

The documentation is available here. Tests are run for Node.js and Bun.

To use the library in your browser, check out simple-data-analysis-flow. You might also find the journalism library and Code Like a Journalist interesting.

The library is maintained by Nael Shiab, computational journalist and senior data producer for CBC News.

@@ -103,4 +103,4 @@

If you want to generate and save charts with Node.js and other runtimes, check the journalism library, more specifically the savePlotChart function.

-
+
diff --git a/docs/modules.html b/docs/modules.html index fbf6bb56..655ffed2 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1,5 +1,5 @@ -Simple-data-analysis - v3.6.2

Simple-data-analysis - v3.6.2

Index

Classes

SimpleDB +Simple-data-analysis - v3.6.3

Simple-data-analysis - v3.6.3

Index

Classes

+