> For the complete documentation index, see [llms.txt](https://gotolabs.gitbook.io/lightninguservault/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gotolabs.gitbook.io/lightninguservault/architecture/data-storage.md).

# Data Storage:

At LightningUserVault, we value flexibility. With our Storage interface, you can easily integrate a variety of storage systems. We currently support `Pebble` for key-value storage and `PostgreSQL` for SQL, but the architecture allows for easy expansion.

✅ **Currently Supported**:

1. `Pebble` (Key-Value)
2. `PostgreSQL` (SQL)

#### 🔌 Storage Interface:

If you're interested in adding more storage options, here's the interface to guide you:

```
type Storage interface {
	// Set stores a value and returns user ID and an error if any issue occurs during the operation
	Set(value string) (int64, error)

	// Get retrieves the value for a given user ID and returns an error if any issue occurs during the operation
	Get(key int64) (*common.User, error)

	// Close closes storage instance
	Close() error
}
```

#### 🧪 **Mock Implementations for Testing**

For developers and testers, we offer mock implementation of database interface

```
package mocks

import "github.com/Aleksao998/LightningUserVault/core/common"

type (
	getDelegate   func(key int64) (*common.User, error)
	setDelegate   func(value string) (int64, error)
	closeDelegate func() error
)

type MockStorage struct {
	GetFn   getDelegate
	SetFn   setDelegate
	CloseFn closeDelegate
}

func (m *MockStorage) Get(key int64) (*common.User, error) {
	if m.GetFn != nil {
		return m.GetFn(key)
	}

	return nil, nil
}

func (m *MockStorage) Set(value string) (int64, error) {
	if m.SetFn != nil {
		return m.SetFn(value)
	}

	return 0, nil
}

func (m *MockStorage) Close() error {
	if m.CloseFn != nil {
		return m.CloseFn()
	}

	return nil
}
```

**Usage example:**

```go
mockStorage := &storageMock.MockStorage{
	GetFn: func(key int64) (*common.User, error) {
		return nil, errUserNotFound
	},
	SetFn: func(value string) (int64, error) {
		return 0, errInternal
	},
}
```
