Skip to content

Commit

Permalink
Fix bug inserter and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc140583 committed Jul 14, 2024
1 parent d0e3caf commit 9367858
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,68 @@
# io
- Utilities to load file, save file, zip file
- Export from database to file
- Import from file
## File Reader
- File Stream Reader
- Delimiter (CSV format) File Reader
- Fix Length File Reader
## File Writer
- File Stream Writer
#### Delimiter (CSV format) Transformer
- Transform an object to Delimiter (CSV) format
- Transform an object to Fix Length format

## Import Data
### Import Flow
![Import flow with data validation](https://cdn-images-1.medium.com/max/800/1*Y4QUN6QnfmJgaKigcNHbQA.png)

#### Layer Architecture
- Popular for web development

![Layer Architecture](https://cdn-images-1.medium.com/max/800/1*JDYTlK00yg0IlUjZ9-sp7Q.png)

#### Hexagonal Architecture
- Suitable for Import Flow

![Hexagonal Architecture](https://cdn-images-1.medium.com/max/800/1*nMu5_jZJ1omzIB5VK5Lh-w.png)

#### Based on the flow, there are 4 main components (4 main ports):
- Reader, Validator, Transformer, Writer
##### Reader
Reader Adapter Sample: File Reader. We provide 2 file reader adapters:
- Delimiter (CSV format) File Reader
- Fix Length File Reader
##### Validator
- Validator Adapter Sample: Schema Validator
- We provide the Schema validator based on GOLANG Tags
##### Transformer
We provide 2 transformer adapters
- Delimiter Transformer (CSV)
- Fix Length Transformer
##### Writer
We provide many writer adapters:
- SQL Writer: to insert or update data
- SQL Inserter: to insert data
- SQL Updater: to update data

- SQL Stream Writer: to insert or update data. When you write data, it keeps the data in the buffer, it does not write data. It just writes data when flush.
- SQL Inserter: to insert data. When you write data, it keeps the data in the buffer, it does not write data. It just writes data when flush. Especially, we build 1 single SQL statement to improve the performance.
- SQL Updater: to update data. When you write data, it keeps the data in the buffer, it does not write data. It just writes data when flush.

- Mongo Writer: to insert or update data
- Mongo Inserter: to insert data
- Mongo Updater: to update data

- Mongo Stream Writer: to insert or update data. When you write data, it keeps the data in the buffer, it does not write data. It just writes data when flush.
- Mongo Inserter: to insert data. When you write data, it keeps the data in the buffer, it does not write data. It just writes data when flush.
- Mongo Updater: to update data. When you write data, it keeps the data in the buffer, it does not write data. It just writes data when flush.

## Installation
Please make sure to initialize a Go module before installing core-go/io:

```shell
go get -u github.com/core-go/io
```

Import:
```go
import "github.com/core-go/io"
```
2 changes: 1 addition & 1 deletion sql/inserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewSqlInserter[T any](db *sql.DB, tableName string, mp func(T), toArray fun
return &Inserter[T]{db: db, BoolSupport: boolSupport, VersionIndex: -1, schema: schema, tableName: tableName, BuildParam: buildParam, Map: mp, ToArray: toArray}
}

func (w *Inserter[T]) Write(ctx context.Context, model interface{}) error {
func (w *Inserter[T]) Write(ctx context.Context, model T) error {
if w.Map != nil {
w.Map(model)
}
Expand Down

0 comments on commit 9367858

Please sign in to comment.