SQLite3


mattn/go-sqlite3를 사용하는 SQLite3 저장소 드라이버입니다.

참고: Go 1.19 이상 버전이 필요합니다.

Table of Contents

  • Signatures

  • Installation

  • Examples

  • Config

  • Default Config

Signatures

func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)  
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s Storage) Conn() sql.DB

Installation

SQLite3는 모듈을 지원하는 Go의 최신 2개 버전에서 테스트되었습니다. 아직 초기화하지 않았다면 먼저 다음을 실행하세요:

go mod init github.com/<user>/<repo>

그런 다음 sqlite3를 설치합니다:

go get github.com/gofiber/storage/sqlite3/v2

Examples

저장소 패키지를 임포트합니다.

import "github.com/gofiber/storage/sqlite3/v2"  

다음과 같은 방법으로 저장소를 생성할 수 있습니다:

// 기본 설정으로 초기화
store := sqlite3.New()

// 사용자 정의 설정으로 초기화 
store := sqlite3.New(sqlite3.Config{
  Database:        "./fiber.sqlite3", 
  Table:           "fiber_storage",
  Reset:           false,
  GCInterval:      10 * time.Second,
  MaxOpenConns:    100,
  MaxIdleConns:    100,  
  ConnMaxLifetime: 1 * time.Second,
})

Config

type Config struct {
  // 데이터베이스 이름
  // 
  // 옵션. 기본값은 "fiber"
  Database string

  // 테이블 이름  
  //
  // 옵션. 기본값은 "fiber_storage"
  Table string

  // Reset은 기존 테이블의 모든 키를 삭제합니다
  // 
  // 옵션. 기본값은 false
  Reset bool
  
  // 만료된 키를 삭제하기 전까지의 시간
  //
  // 옵션. 기본값은 10 * time.Second
  GCInterval time.Duration

  // //////////////////////////////////////
  // 어댑터 관련 설정 옵션                //  
  // //////////////////////////////////////

  // MaxIdleConns는 유휴 연결 풀에 있는 최대 연결 수를 설정합니다.
  // 
  // 옵션. 기본값은 100
  MaxIdleConns int

  // MaxOpenConns는 데이터베이스에 대한 최대 열린 연결 수를 설정합니다.
  //
  // 옵션. 기본값은 100
  MaxOpenConns int

  // ConnMaxLifetime은 연결이 재사용될 수 있는 최대 시간을 설정합니다. 
  //  
  // 옵션. 기본값은 1초
  ConnMaxLifetime time.Duration
}

Default Config

var ConfigDefault = Config{
  Database:        "./fiber.sqlite3",
  Table:           "fiber_storage", 
  Reset:           false,
  GCInterval:      10 * time.Second,
  MaxOpenConns:    100,
  MaxIdleConns:    100,
  ConnMaxLifetime: 1 * time.Second,  
}

Last updated