https://github.com/crossevol/sqlcc
generate basic sql statements for sqlc
https://github.com/crossevol/sqlcc
cmd go golang sql sqlc
Last synced: 8 months ago
JSON representation
generate basic sql statements for sqlc
- Host: GitHub
- URL: https://github.com/crossevol/sqlcc
- Owner: CrossEvol
- License: other
- Created: 2024-05-27T11:08:34.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-01T12:30:21.000Z (about 2 years ago)
- Last Synced: 2025-01-13T23:35:07.160Z (over 1 year ago)
- Topics: cmd, go, golang, sql, sqlc
- Language: Go
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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
```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
```postgresql
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
```sqlite
PRAGMA table_info('Todo');
PRAGMA table_info(?);
```
## how to verify a column is pk && auto_increment
### sqlite
```sqlite
PRAGMA table_info(downloaded_image);
```
### mysql
`auto_increment`
```mysql
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'answer'
AND TABLE_NAME = 'activity'
AND EXTRA = 'auto_increment';
```
`primary key`
```mysql
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = 'answer'
AND TABLE_NAME = 'activity'
AND CONSTRAINT_NAME = 'PRIMARY';
```
### postgres
`auto_increment`
```postgresql
SELECT column_name, is_identity, column_default
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'Post' AND column_default LIKE 'nextval(%';
```