SQL defines methods that can be used to build a SQL query with chainable method calls. Queries are immutable, so every call to any method will return a new pointer, if you want to build a query using variables you need to reassign them, like this: a = builder.Select("name").From("foo") // "a" is
| 39 | // |
| 40 | // a = a.Where(...) // "a" is reassigned and points to a different address. |
| 41 | type SQL interface { |
| 42 | |
| 43 | // Select initializes and returns a Selector, it accepts column names as |
| 44 | // parameters. |
| 45 | // |
| 46 | // The returned Selector does not initially point to any table, a call to |
| 47 | // From() is required after Select() to complete a valid query. |
| 48 | // |
| 49 | // Example: |
| 50 | // |
| 51 | // q := sqlbuilder.Select("first_name", "last_name").From("people").Where(...) |
| 52 | Select(columns ...interface{}) Selector |
| 53 | |
| 54 | // SelectFrom creates a Selector that selects all columns (like SELECT *) |
| 55 | // from the given table. |
| 56 | // |
| 57 | // Example: |
| 58 | // |
| 59 | // q := sqlbuilder.SelectFrom("people").Where(...) |
| 60 | SelectFrom(table ...interface{}) Selector |
| 61 | |
| 62 | // InsertInto prepares and returns an Inserter targeted at the given table. |
| 63 | // |
| 64 | // Example: |
| 65 | // |
| 66 | // q := sqlbuilder.InsertInto("books").Columns(...).Values(...) |
| 67 | InsertInto(table string) Inserter |
| 68 | |
| 69 | // DeleteFrom prepares a Deleter targeted at the given table. |
| 70 | // |
| 71 | // Example: |
| 72 | // |
| 73 | // q := sqlbuilder.DeleteFrom("tasks").Where(...) |
| 74 | DeleteFrom(table string) Deleter |
| 75 | |
| 76 | // Update prepares and returns an Updater targeted at the given table. |
| 77 | // |
| 78 | // Example: |
| 79 | // |
| 80 | // q := sqlbuilder.Update("profile").Set(...).Where(...) |
| 81 | Update(table string) Updater |
| 82 | |
| 83 | // Exec executes a SQL query that does not return any rows, like sql.Exec. |
| 84 | // Queries can be either strings or upper-db statements. |
| 85 | // |
| 86 | // Example: |
| 87 | // |
| 88 | // sqlbuilder.Exec(`INSERT INTO books (title) VALUES("La Ciudad y los Perros")`) |
| 89 | Exec(query interface{}, args ...interface{}) (sql.Result, error) |
| 90 | |
| 91 | // ExecContext executes a SQL query that does not return any rows, like sql.ExecContext. |
| 92 | // Queries can be either strings or upper-db statements. |
| 93 | // |
| 94 | // Example: |
| 95 | // |
| 96 | // sqlbuilder.ExecContext(ctx, `INSERT INTO books (title) VALUES(?)`, "La Ciudad y los Perros") |
| 97 | ExecContext(ctx context.Context, query interface{}, args ...interface{}) (sql.Result, error) |
| 98 |
no outgoing calls
no test coverage detected