Go Fiber 한글 공식 문서
  • 🙇‍♀️안녕하세요
  • 🏠Home
    • 👋Welcome
    • 📁API
      • 📦Fiber
      • 🚀App
      • 🧠Ctx
      • 📋Constants
      • 🌎Client
      • 📃Log
      • 🧬Middleware
        • Adaptor
        • BasicAuth
        • Cache
        • Compress
        • CORS
        • CSRF
        • EarlyData
        • Encrypt Cookie
        • EnvVar
        • ETag
        • ExpVar
        • Favicon
        • FileSystem
        • Health Check
        • Helmet
        • Idempotency
        • Keyauth
        • Limiter
        • Logger
        • Monitor
        • Pprof
        • Proxy
        • Recover
        • Redirect
        • RequestID
        • Rewrite
        • Session
        • Skip
        • Timeout
    • 📁Guide
      • 🔌Routing
      • 🎭Grouping
      • 📝Templates
      • 🐛Error Handling
      • 🔎Validation
      • 🎣Hooks
      • ⚡Make Fiber Faster
    • 📁Extra
      • 🤔FAQ
      • 📊Benchmarks
  • 🧩Extra
    • 🧬Contrip
      • 👋Welcome
      • Casbin
      • Fgprof
      • Fiberi18n
      • Fibernewrelic
      • Fibersentry
      • Fiberzap
      • Fiberzerolog
      • JWT
      • LoadShed
      • Opafiber
      • Otelfiber
        • Example
      • Paseto
      • README
      • Swagger
      • Websocket
    • 📦Storage
      • 👋Welcome
      • ArangoDB
      • Azure Blob
      • Badger
      • Bbolt
      • Coherence
      • Couchbase
      • DynamoDB
      • Etcd
      • Memcache
      • Memory
      • Minio
      • MongoDB
      • MSSQL
      • MySQL
      • Nats
      • Pebble
      • Postgres
      • Redis
      • Ristretto
      • Rueidis
      • S3
      • ScyllaDb
      • SQLite3
    • 📃Template
      • 👋Welcome
      • Ace
      • Amber
      • Django
      • Handlebars
      • HTML
        • Golang Templates Cheatsheet
      • Jet
      • Mustache
      • Pug
      • Slim
Powered by GitBook
On this page
  • Table of Contents
  • Signatures
  • Installation
  • Examples
  • Config
  • Default Config
  1. Extra
  2. Storage

SQLite3

PreviousScyllaDbNextTemplate

Last updated 1 year ago


를 사용하는 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

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,  
}

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

🧩
📦
Go의 최신 2개 버전
mattn/go-sqlite3