Mosql.SQL (mosql v0.1.0)

Link to this section Summary

Functions

SQL for adding a new column if it does not exists

Generates upsert SQL statement for a given schema and a list of values of values INSERT INTO <table_name> (column1, column2...) VALUES (value1, value2...), (value1, value2...), (value1, value2...).... ON CONFLICT (primary_key_field) DO UPDATE SET column = EXCLUDED.column...;

Generates a SQL string for creating a table if not exists

Generates a SQL string for creating a table

SQL for drop table

Prepare the SQL DB for the full export. It performs the following 3 steps

SQL for removing a column if it does exists

Generates a SQL string for checking if a table exists in the schema

Construct the insert values for a given schema and a mongo document

SQL for truncate table

Generates upsert SQL statement for a given schema and a mongo document INSERT INTO <table_name> (column1, column2...) VALUES (value1, value2...) ON CONFLICT (primary_key_field) DO UPDATE SET column = EXCLUDED.column...;

Link to this section Functions

Link to this function

add_column_if_not_exists_sql(schema, column)

SQL for adding a new column if it does not exists

Link to this function

alter_table(schema, db_name)

Link to this function

alter_tables(export)

Link to this function

bulk_upsert_sql(schema, values)

Generates upsert SQL statement for a given schema and a list of values of values INSERT INTO <table_name> (column1, column2...) VALUES (value1, value2...), (value1, value2...), (value1, value2...).... ON CONFLICT (primary_key_field) DO UPDATE SET column = EXCLUDED.column...;

Link to this function

create_table_if_not_exists_sql(schema)

Generates a SQL string for creating a table if not exists

Link to this function

create_table_with_columns_sql(schema)

Generates a SQL string for creating a table

CREATE TABLE [IF NOT EXISTS] table_name (

column1 datatype(length) column_contraint,
column2 datatype(length) column_contraint,
column3 datatype(length) column_contraint,
...
table_constraints

);

Link to this function

drop_table_sql(schema)

SQL for drop table

Link to this function

filter_missing_columns(schema_columns, existing_columns)

Link to this function

filter_new_columns(schema_columns, existing_columns)

Link to this function

mongo_to_sql_type(mongo_type)

Link to this function

prepare(export)

Prepare the SQL DB for the full export. It performs the following 3 steps:

1. Truncate data from tables if exists
2. Create new tables, if not exists
3. Alter existing tables, if schema changed
Link to this function

remove_column_if_exists_sql(schema, column)

SQL for removing a column if it does exists

Link to this function

table_columns(db, table)

Link to this function

table_exists(schema)

Link to this function

table_exists_sql(schema)

Generates a SQL string for checking if a table exists in the schema

Link to this function

to_insert_values(schema, mongo_document \\ %{})

Construct the insert values for a given schema and a mongo document

Link to this function

truncate_table_sql(schema)

SQL for truncate table

Link to this function

upsert_document_sql(schema, mongo_document \\ %{})

Generates upsert SQL statement for a given schema and a mongo document INSERT INTO <table_name> (column1, column2...) VALUES (value1, value2...) ON CONFLICT (primary_key_field) DO UPDATE SET column = EXCLUDED.column...;