https://github.com/jilio/sqlitefs
sqlite as a filesystem for golang apps
https://github.com/jilio/sqlitefs
golang sqlite
Last synced: 1 day ago
JSON representation
sqlite as a filesystem for golang apps
- Host: GitHub
- URL: https://github.com/jilio/sqlitefs
- Owner: jilio
- License: mit
- Created: 2022-02-02T17:18:40.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-12-01T13:25:57.000Z (about 2 months ago)
- Last Synced: 2025-12-03T07:12:29.587Z (about 1 month ago)
- Topics: golang, sqlite
- Language: Go
- Homepage:
- Size: 6.28 MB
- Stars: 25
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SQLiteFS
SQLiteFS is a Go package that implements the `fs.FS` interface using SQLite as a storage backend. This allows you to store and access files directly from a SQLite database, which can be useful for embedded applications, resource-constrained systems, or when you need a unified storage for both files and metadata.
## Features
- Implementation of the `fs.FS` interface
- File storage in SQLite database
- Support for concurrent writes through a shared channel
- Fragmented file storage for efficient handling of large files
- Automatic MIME type detection for files
## Installation
To use SQLiteFS in your Go project, run the following command:
```sh
go get github.com/jilio/sqlitefs
```
## Usage
Here's a simple example of how to use SQLiteFS:
```go
package main
import (
"database/sql"
"fmt"
"io/fs"
"log"
"github.com/jilio/sqlitefs"
_ "modernc.org/sqlite"
)
func main() {
// Open a connection to the SQLite database
db, err := sql.Open("sqlite", "files.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Create a new instance of SQLiteFS
sqliteFS, err := sqlitefs.NewSQLiteFS(db)
if err != nil {
log.Fatal(err)
}
defer sqliteFS.Close()
// Write a file
writer := sqliteFS.NewWriter("example.txt")
_, err = writer.Write([]byte("Hello, SQLiteFS!"))
if err != nil {
log.Fatal(err)
}
err = writer.Close()
if err != nil {
log.Fatal(err)
}
// Read a file
file, err := sqliteFS.Open("example.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
content, err := fs.ReadFile(sqliteFS, "example.txt")
if err != nil {
log.Fatal(err)
}
fmt.Printf("File content: %s\n", content)
}
```
## License
[MIT License](LICENSE)