Skip to content

Latest commit

 

History

History
63 lines (53 loc) · 1.49 KB

README.md

File metadata and controls

63 lines (53 loc) · 1.49 KB

This repo is a helper tool for sqlc.

Todo

when generate insert or update stmt, should remove the id column based on generated approarch

Notes

how to get column name from database

mysql

SELECT DISTINCT COLUMN_NAME, COLUMN_TYPE FROM information_schema.`COLUMNS` WHERE TABLE_NAME = 'activity' AND
TABLE_SCHEMA = 'answer';
SELECT DISTINCT COLUMN_NAME, COLUMN_TYPE FROM information_schema.`COLUMNS` WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?;

postgres

SELECT DISTINCT "column_name", data_type FROM information_schema.COLUMNS WHERE table_schema = 'public' AND "
table_name" = 'Post';
SELECT DISTINCT "column_name", data_type FROM information_schema.COLUMNS WHERE table_schema = 'public' AND "
table_name" = ?;

sqlite

PRAGMA table_info('Todo');
PRAGMA table_info(?);

how to verify a column is pk && auto_increment

sqlite

PRAGMA table_info(downloaded_image);

mysql

auto_increment

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'answer'
AND TABLE_NAME = 'activity'
AND EXTRA = 'auto_increment';

primary key

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = 'answer'
AND TABLE_NAME = 'activity'
AND CONSTRAINT_NAME = 'PRIMARY';

postgres

auto_increment

SELECT column_name, is_identity, column_default
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'Post' AND column_default LIKE 'nextval(%';