proxy.golang.org : github.com/jjeffery/sqlrow
Package sqlrow makes it easy to construct and execute SQL queries for common, row-based scenarios. Supported scenarios include: This package is intended for programmers who are comfortable with writing SQL, but would like assistance with the sometimes tedious process of preparing SELECT, INSERT, UPDATE and DELETE statements for tables that have a large number of columns. This package is designed to work seamlessly with the standard library "database/sql" package. It does not provide any layer on top of *sql.DB or *sql.Tx. If the calling program has a need to execute queries independently of this package, it can use "database/sql" directly, or make use of any other third party package that uses "database/sql". Package sqlrow uses reflection on the supplied row to provide assistance with creating SQL. This assistance is particularly useful for tables with many columns, but the following examples use this simple structure: For a row of type UserRow the following INSERT query: will be translated into the following, depending on the SQL dialect: In the above example note that the "id" column is not inserted. This is because it is defined as an auto-increment column. If it were not an auto-increment column it would be included in the column list. This pattern is so common for inserting individual rows that, for convenience, providing just the table name has the same result: The following UPDATE query: will be translated into the following: This pattern is so common for inserting individual rows that, for convenience, providing just the table name has the same result: It is possible to construct more complex UPDATE statements. The following example can be useful for rows that make use of optimistic locking: DELETE queries are similar to UPDATE queries: and are both translated as (for MySQL, SQLite): SQL SELECT queries can be constructed easily is translated as (for MySQL, SQLite): More complex queries involving joins and table aliases are possible: is translated as (for MySQL, SQLite): Package sqlrow makes use of reflection in order to build the SQL that is sent to the database server, and this imposes a performance penalty. In order to reduce this overhead the package caches queries generated. The end result is that the performance of this package is close to the performance of code that uses hand-constructed SQL queries to call package "database/sql" directly. More information about this package can be found at https://github.com/jjeffery/sqlrow.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/jjeffery/sqlrow
License: MIT
Latest release: about 8 years ago
First release: about 8 years ago
Namespace: github.com/jjeffery
Last synced: 4 months ago