Skip to content

Latest commit

 

History

History
77 lines (65 loc) · 1.64 KB

query_scaffolding.md

File metadata and controls

77 lines (65 loc) · 1.64 KB

Using the typesql cli to scaffold your sql queries can be a time saver. You can adjust them according your needs.

Command:

typesql generate <option> <sql-name>
typesql g <option> <sql-name>

option alias example
select s typesql generate select select-user.sql
insert i typesql generate insert insert-user.sql
update u typesql generate update update-user.sql
delete d typesql generate delete delete-user.sql

Examples:

SELECT:

typesql generate select select-employees.sql --table employees will generate the following in the file sqls/select-employees.sql.

SELECT
    emp_no,
    birth_date,
    first_name,
    last_name,
    gender,
    hire_date
FROM employees

INSERT:

typesql generate insert insert-employee.sql --table employees will generate the following in the file sqls/insert-employee.sql.

INSERT INTO employees
(
    emp_no,
    birth_date,
    first_name,
    last_name,
    gender,
    hire_date
)
VALUES
(
    :emp_no,
    :birth_date,
    :first_name,
    :last_name,
    :gender,
    :hire_date
)

UPDATE

typesql generate update update-employee.sql --table employees will generate the following in the file sqls/update-employee.sql.

UPDATE employees
SET
    emp_no = :emp_no,
    birth_date = :birth_date,
    first_name = :first_name,
    last_name = :last_name,
    gender = :gender,
    hire_date = :hire_date
WHERE
    emp_no = :emp_no

DELETE

typesql generate delete delete-employee.sql --table employees will generate the following in the file sqls/delete-employee.sql.

DELETE FROM employees
WHERE emp_no = :emp_no