Skip to content

moxar/walker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Walker

Godoc license

Walks around the database's schema, establish relations between tables, and build the FROM ... JOIN clauses dynamicaly.

Checkout test file and the test samples for examples of usage.

Features

The package builds the FROM ... JOIN clause of a SQL query based on the required tables. It needs a schema declaration, that can be hardcoded or fetched from the db (see mysql package).

MySQL

The walker/mysql provides a function that loads the schema from the database.

// Fetch the schema from database.
schema, err := mysql.LoadSchema(ctx, db, "my_project_db")
if err != nil {
	// ...
}

// Alias lands table to countries.
schema.Alias("lands", "countries")

// Prepare the graph.
graph, err := walker.NewGraph(schema)
if err != nil {
	// ...
}

// Build the query relating users, cities and countries.
from, err := graph.From("users", "cities, "countries")
if err != nil {
	// ...
}