MCPcopy
hub / github.com/dosco/graphjin / Example_multiDBQueryPostgres

Function Example_multiDBQueryPostgres

tests/multidb_test.go:39–70  ·  view source on GitHub ↗

Example_multiDBQueryPostgres tests querying the PostgreSQL database directly

()

Source from the content-addressed store, hash-verified

37
38// Example_multiDBQueryPostgres tests querying the PostgreSQL database directly
39func Example_multiDBQueryPostgres() {
40 // Skip if not in multi-DB mode
41 if !requireMultiDB() {
42 fmt.Println(`{"users":[{"email":"user1@test.com","full_name":"User 1","id":1}]}`)
43 return
44 }
45
46 gql := `query {
47 users(limit: 1, order_by: { id: asc }) {
48 id
49 full_name
50 email
51 }
52 }`
53
54 conf := newMultiDBConfig(&core.Config{DisableAllowList: true})
55 conf.Tables = multiDBTables()
56
57 gj, err := newMultiDBGraphJin(conf)
58 if err != nil {
59 fmt.Println(err)
60 return
61 }
62
63 res, err := gj.GraphQL(context.Background(), gql, nil, nil)
64 if err != nil {
65 fmt.Println(err)
66 } else {
67 printJSON(res.Data)
68 }
69 // Output: {"users":[{"email":"user1@test.com","full_name":"User 1","id":1}]}
70}
71
72// Example_multiDBQuerySQLite tests querying the SQLite database
73func Example_multiDBQuerySQLite() {

Callers

nothing calls this directly

Calls 6

requireMultiDBFunction · 0.85
newMultiDBConfigFunction · 0.85
multiDBTablesFunction · 0.85
newMultiDBGraphJinFunction · 0.85
printJSONFunction · 0.85
GraphQLMethod · 0.45

Tested by

no test coverage detected