sqlutils

package
v0.0.0-...-4275e79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2022 License: Unlicense Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AvaialableBackends = map[string]SQLBackend{
	"sqlite":   SQLiteBackend{},
	"mysql":    MySQLBackend{},
	"postgres": PostgresBackend{},
}

Functions

This section is empty.

Types

type Metadata

type Metadata struct {
	Inode int64 `db:"inode"`

	Uid int64 `db:"uid"`
	Gid int64 `db:"gid"`

	Mode int64 `db:"mode"`
	Type int64 `db:"type"`

	Ctime int64 `db:"ctime"`
	Atime int64 `db:"atime"`
	Mtime int64 `db:"mtime"`

	Name string `db:"name"`
	Size int64  `db:"size"`
}

Metadata table as go struct

type MySQLBackend

type MySQLBackend struct {
	// contains filtered or unexported fields
}

func (MySQLBackend) CreateDBTables

func (m MySQLBackend) CreateDBTables(db *sql.DB) error

CreateDBTables creates db tables using sql file

func (MySQLBackend) CreateDirUnderInode

func (d MySQLBackend) CreateDirUnderInode(db *sql.DB, inode int32, name string) (int32, error)

CreateDirUnderInode creates a Dir named name under directory referred to by inode

func (MySQLBackend) CreateFileUnderInode

func (d MySQLBackend) CreateFileUnderInode(db *sql.DB, inode int32, name string) (int32, error)

CreateFileUnderInode creates a File named name under directory referred to by inode

func (MySQLBackend) GetDirectoryContentsForInode

func (d MySQLBackend) GetDirectoryContentsForInode(db *sql.DB, inode int32) ([]int32, error)

GetDirectoryContentsForInode returns all children of inode from db

func (MySQLBackend) GetFileContentsForInode

func (d MySQLBackend) GetFileContentsForInode(db *sql.DB, inode int32) ([]byte, error)

GetFileContentsForInode reads file contents for inode from db

TODO: split contents into blocks

func (MySQLBackend) GetMetadataForInode

func (d MySQLBackend) GetMetadataForInode(db *sql.DB, inode int32) (Metadata, error)

GetMetadataForInode retrieves metadata for a given inode from db

func (MySQLBackend) InitializeDBRows

func (d MySQLBackend) InitializeDBRows(db *sql.DB) error

InitializeDBRows creates the necessary rows for fs to function

Currently, only root metadata is setup

func (MySQLBackend) OpenDB

func (m MySQLBackend) OpenDB(dsn string) (*sql.DB, error)

OpenDB enables multiStatements and connects to dsn

func (MySQLBackend) RemoveDirUnderInode

func (d MySQLBackend) RemoveDirUnderInode(db *sql.DB, inode int32, name string) error

RemoveDirUnderInode removes Dir named name from directory referred to by inode

func (MySQLBackend) RemoveFileUnderInode

func (d MySQLBackend) RemoveFileUnderInode(db *sql.DB, inode int32, name string) error

RemoveFileUnderInode removes File named name from directory referred to by inode

func (MySQLBackend) SetFileContentsForInode

func (d MySQLBackend) SetFileContentsForInode(db *sql.DB, inode int32, data []byte) error

SetFileContentsForInode updates file content for inode on db

func (MySQLBackend) SetMetadataForInode

func (d MySQLBackend) SetMetadataForInode(db *sql.DB, inode int32, metadata Metadata) error

SetMetadataForInode updates metadata for inode on db

func (MySQLBackend) VerifyDB

func (d MySQLBackend) VerifyDB(db *sql.DB) error

VerifyDB does pretty basic check for whether the necessary tables were created. This check might pass and later operations still might fail.

TODO: do more extensive checks

type PostgresBackend

type PostgresBackend struct {
	// contains filtered or unexported fields
}

func (PostgresBackend) CreateDBTables

func (p PostgresBackend) CreateDBTables(db *sql.DB) error

CreateDBTables creates db tables using sql file

func (PostgresBackend) CreateDirUnderInode

func (d PostgresBackend) CreateDirUnderInode(db *sql.DB, inode int32, name string) (int32, error)

CreateDirUnderInode creates a Dir named name under directory referred to by inode

func (PostgresBackend) CreateFileUnderInode

func (d PostgresBackend) CreateFileUnderInode(db *sql.DB, inode int32, name string) (int32, error)

CreateFileUnderInode creates a File named name under directory referred to by inode

func (PostgresBackend) GetDirectoryContentsForInode

func (d PostgresBackend) GetDirectoryContentsForInode(db *sql.DB, inode int32) ([]int32, error)

GetDirectoryContentsForInode returns all children of inode from db

func (PostgresBackend) GetFileContentsForInode

func (d PostgresBackend) GetFileContentsForInode(db *sql.DB, inode int32) ([]byte, error)

GetFileContentsForInode reads file contents for inode from db

TODO: split contents into blocks

func (PostgresBackend) GetMetadataForInode

func (d PostgresBackend) GetMetadataForInode(db *sql.DB, inode int32) (Metadata, error)

GetMetadataForInode retrieves metadata for a given inode from db

func (PostgresBackend) InitializeDBRows

func (d PostgresBackend) InitializeDBRows(db *sql.DB) error

InitializeDBRows creates the necessary rows for fs to function

Currently, only root metadata is setup

func (PostgresBackend) OpenDB

func (p PostgresBackend) OpenDB(dsn string) (*sql.DB, error)

OpenDB connects to dsn

func (PostgresBackend) RemoveDirUnderInode

func (d PostgresBackend) RemoveDirUnderInode(db *sql.DB, inode int32, name string) error

RemoveDirUnderInode removes Dir named name from directory referred to by inode

func (PostgresBackend) RemoveFileUnderInode

func (d PostgresBackend) RemoveFileUnderInode(db *sql.DB, inode int32, name string) error

RemoveFileUnderInode removes File named name from directory referred to by inode

func (PostgresBackend) SetFileContentsForInode

func (d PostgresBackend) SetFileContentsForInode(db *sql.DB, inode int32, data []byte) error

SetFileContentsForInode updates file content for inode on db

func (PostgresBackend) SetMetadataForInode

func (d PostgresBackend) SetMetadataForInode(db *sql.DB, inode int32, metadata Metadata) error

SetMetadataForInode updates metadata for inode on db

func (PostgresBackend) VerifyDB

func (d PostgresBackend) VerifyDB(db *sql.DB) error

VerifyDB does pretty basic check for whether the necessary tables were created. This check might pass and later operations still might fail.

TODO: do more extensive checks

type SQLBackend

type SQLBackend interface {
	OpenDB(dsn string) (*sql.DB, error)
	VerifyDB(db *sql.DB) error

	CreateDBTables(db *sql.DB) error
	InitializeDBRows(db *sql.DB) error

	GetMetadataForInode(db *sql.DB, inode int32) (Metadata, error)
	SetMetadataForInode(db *sql.DB, inode int32, metadata Metadata) error

	GetDirectoryContentsForInode(db *sql.DB, inode int32) ([]int32, error)

	GetFileContentsForInode(db *sql.DB, inode int32) ([]byte, error)
	SetFileContentsForInode(db *sql.DB, inode int32, data []byte) error

	// could've been the same function with an if condition
	// but maybe some backends might want to utilize the segregation
	CreateDirUnderInode(db *sql.DB, inode int32, name string) (int32, error)
	CreateFileUnderInode(db *sql.DB, inode int32, name string) (int32, error)

	// could've been the same function with an if condition
	// but maybe some backends might want to utilize the segregation
	RemoveDirUnderInode(db *sql.DB, inode int32, name string) error
	RemoveFileUnderInode(db *sql.DB, inode int32, name string) error
}

type SQLiteBackend

type SQLiteBackend struct {
	// contains filtered or unexported fields
}

func (SQLiteBackend) CreateDBTables

func (s SQLiteBackend) CreateDBTables(db *sql.DB) error

CreateDBTables creates db tables using sql file

func (SQLiteBackend) CreateDirUnderInode

func (d SQLiteBackend) CreateDirUnderInode(db *sql.DB, inode int32, name string) (int32, error)

CreateDirUnderInode creates a Dir named name under directory referred to by inode

func (SQLiteBackend) CreateFileUnderInode

func (d SQLiteBackend) CreateFileUnderInode(db *sql.DB, inode int32, name string) (int32, error)

CreateFileUnderInode creates a File named name under directory referred to by inode

func (SQLiteBackend) GetDirectoryContentsForInode

func (d SQLiteBackend) GetDirectoryContentsForInode(db *sql.DB, inode int32) ([]int32, error)

GetDirectoryContentsForInode returns all children of inode from db

func (SQLiteBackend) GetFileContentsForInode

func (d SQLiteBackend) GetFileContentsForInode(db *sql.DB, inode int32) ([]byte, error)

GetFileContentsForInode reads file contents for inode from db

TODO: split contents into blocks

func (SQLiteBackend) GetMetadataForInode

func (d SQLiteBackend) GetMetadataForInode(db *sql.DB, inode int32) (Metadata, error)

GetMetadataForInode retrieves metadata for a given inode from db

func (SQLiteBackend) InitializeDBRows

func (d SQLiteBackend) InitializeDBRows(db *sql.DB) error

InitializeDBRows creates the necessary rows for fs to function

Currently, only root metadata is setup

func (SQLiteBackend) OpenDB

func (s SQLiteBackend) OpenDB(dsn string) (*sql.DB, error)

OpenDB connects to dsn

func (SQLiteBackend) RemoveDirUnderInode

func (d SQLiteBackend) RemoveDirUnderInode(db *sql.DB, inode int32, name string) error

RemoveDirUnderInode removes Dir named name from directory referred to by inode

func (SQLiteBackend) RemoveFileUnderInode

func (d SQLiteBackend) RemoveFileUnderInode(db *sql.DB, inode int32, name string) error

RemoveFileUnderInode removes File named name from directory referred to by inode

func (SQLiteBackend) SetFileContentsForInode

func (d SQLiteBackend) SetFileContentsForInode(db *sql.DB, inode int32, data []byte) error

SetFileContentsForInode updates file content for inode on db

func (SQLiteBackend) SetMetadataForInode

func (d SQLiteBackend) SetMetadataForInode(db *sql.DB, inode int32, metadata Metadata) error

SetMetadataForInode updates metadata for inode on db

func (SQLiteBackend) VerifyDB

func (d SQLiteBackend) VerifyDB(db *sql.DB) error

VerifyDB does pretty basic check for whether the necessary tables were created. This check might pass and later operations still might fail.

TODO: do more extensive checks

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL