20260627165246
This commit is contained in:
1 parent
5983d29128
commit
bfb2b6037b
25 files changed
+2665
-518
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
sqlBytes, err := os.ReadFile("db/finance_category.sql")
|
||||
must(err)
|
||||
|
||||
conn, err := pgx.Connect(ctx, "postgres://postgres:zhang520..@117.72.182.135:5432/allapp?sslmode=disable")
|
||||
must(err)
|
||||
defer conn.Close(ctx)
|
||||
|
||||
_, err = conn.Exec(ctx, string(sqlBytes))
|
||||
must(err)
|
||||
|
||||
fmt.Println("finance category schema applied")
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
conn, err := pgx.Connect(ctx, "postgres://postgres:zhang520..@117.72.182.135:5432/allapp?sslmode=disable")
|
||||
must(err)
|
||||
defer conn.Close(ctx)
|
||||
|
||||
rows, err := conn.Query(ctx, `
|
||||
select table_name, column_name, data_type
|
||||
from information_schema.columns
|
||||
where table_schema = 'public'
|
||||
and table_name in ('b_finance_category', 'b_finance_category_default')
|
||||
order by table_name, ordinal_position
|
||||
`)
|
||||
must(err)
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var tableName, columnName, dataType string
|
||||
must(rows.Scan(&tableName, &columnName, &dataType))
|
||||
fmt.Printf("%s.%s %s\n", tableName, columnName, dataType)
|
||||
}
|
||||
must(rows.Err())
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user