# README
sql
- It is the library to work with "database/sql" of GO SDK to offer some advantages:
Simplified Database Operations
- Simplify common database operations, such as CRUD (Create, Read, Update, Delete) operations, transactions, and batch processing, by providing high-level abstractions and utilities.
Compatibility and Flexibility
- It is compatible with various SQL databases such as Postgres, My SQL, MS SQL, Oracle, SQLite, offer flexibility in terms of database driver selection, and query building capabilities.
Performance Optimizations
Some use cases that we optimize the performance:
- When insert many rows, we build a single SQL statement and execute once. The syntax of Oracle is different from Postgres, My SQL, MS SQL, SQLite.
- Source code to build dynamic SQL statement is here, and the sample is at project-samples/go-import
- When you want to insert or update, we build a single SQL statement.
- Cons: The syntax is specified for Oracle, MS SQL, Postgres, My SQL, SQLite. So, source code is long and complicated.
- Props: Because it interacts with DB once, it has a better performance.
Reduced Boilerplate Code
- Reduce boilerplate code associated with database interactions, allowing developers to focus more on application logic rather than low-level database handling
- In this layer architecture sample, you can see we can reduce a lot of source code at data access layer, or you use generic repository to replace all repository source code.
Some advantage features
Decimal
- Support decimal, which is useful for currency
Query Template (SQL Mapper)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mappers">
<select id="user">
select *
from users
where
<if test="username != null">
username like #{username} and
</if>
<if test="displayName != null">
displayName like #{displayName} and
</if>
<if test="status != null">
status in (#{status}) and
</if>
<if test="q != null">
(username like #{q} or displayName like #{q} or email like #{q}) and
</if>
1 = 1
<if test="sort != null">
order by {sort}
</if>
<if test="sort == null">
order by userId
</if>
</select>
</mapper>
Generic Repository (CRUD repository)
- It is like CrudRepository of Spring, which promotes rapid development and consistency across applications.
- While it provides many advantages, such as reducing boilerplate code and ensuring transactional integrity, it also offers flexibility and control over complex queries, because it uses "database/sql" at GO SDK level.
- Especially, it also supports composite primary key.
- You can look at the sample at go-sql-composite-key.
- In this sample, the company_users has 2 primary keys: company_id and user_id
- You can define a GO struct, which contains 2 fields: CompanyId and UserId
package model type UserId struct { CompanyId string `json:"companyId" gorm:"column:company_id;primary_key"` UserId string `json:"userId" gorm:"column:user_id;primary_key"` }
Search Repository
The flow for search/paging:
- Build the dynamic query
- Build the paging query from dynamic query (it specified for Oracle, Postgres, My SQL, MS SQL, SQLite)
- Query data and map to array of struct
- Build the count query
- Count the total records for paging
Dynamic query builder
- Look at this sample user, you can see it automatically build a dynamic query for serach.
|
|
Utilities to simplified Database Operations
Simplify data querying: support to map *sql.Rows to array of struct
- For example in this file adapter.go, you can see it reduces a lot of source code.
|
|
Utility functions to build sql statement to insert, update, insert or update
- For example in this file adapter.go, you can see it reduces a lot of source code.
|
|
Simplify transaction handling
- For example, in this service layer and this data access layer, it simplifies transaction handling, at GO SDK level.
|
|
- In another example, in this service layer and this data access layer, it simplifies transaction handling, at GO SDK level.
|
|
For batch job
- Inserter
- Updater
- Writer
- StreamInserter
- StreamUpdater
- StreamWriter
- BatchInserter
- BatchUpdater
- BatchWriter
Health Check
Passcode Adapter
Action Log
- Save Action Log with dynamic database design
Field Loader
Installation
Please make sure to initialize a Go module before installing core-go/sql:
go get -u github.com/core-go/sql
Import:
import "github.com/core-go/sql"
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
For DefaultGenericService.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Check if string value is contained in slice.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Obtain columns and values required for insert from interface.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
for Loader.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
For ViewDefaultRepository.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
For Search.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Row.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Enable map keys to be retrieved in same order when iterating.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
Field model field definition.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author