sqlite3

package module
v0.0.0-...-7008d3c Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: BSD-3-Clause Imports: 7 Imported by: 3

README

sqlite3

GoDoc Build Status

sqlite3 is a pure Go package decoding the SQLite file format as described by: http://www.sqlite.org/fileformat.html

Current status

WIP: The near-term aim for sqlite3 is to iterate through the data in tables in SQLite files: ie., readonly access, and no actual SQL queries.

It doesn't quite do that yet: so far it just parses the sqlite_master data enough to find a list of tables and their names.

Installation

$ go get github.com/go-sqlite/sqlite3

License

sqlite3 is released under the BSD-3 license.

Example

package main

import (
	"fmt"

	"github.com/go-sqlite/sqlite3"
)

func main() {
	db, err := sqlite3.Open("test.sqlite")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	for _, table := range db.Tables() {
		fmt.Printf(">>> table=%#v\n", table)
	}
}

Contributing

We're always looking for new contributing finding bugs, fixing issues, or writing some docs. If you're interested in contriburing source code changes you'll just need to pull down the source code. You can run tests with go test ./... in the root of this project.

Make sure to add yourself to AUTHORS and CONTRIBUTORS if you submit a PR. We want you to take credit for your work!

Documentation

Overview

Package sqlite3 decodes the SQLite-3 file format.

Index

Constants

View Source
const (
	BTreeInteriorIndexKind = zeroDataKind
	BTreeInteriorTableKind = leafDataKind | intKeyKind
	BTreeLeafIndexKind     = zeroDataKind | leafKind
	BTreeLeafTableKind     = leafDataKind | intKeyKind | leafKind
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

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

Column describes a column in a SQLite table

func (*Column) Name

func (col *Column) Name() string

Name returns the name of the column

func (*Column) Type

func (col *Column) Type() reflect.Type

Type returns the SQLite type of the column

type DbFile

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

func Open

func Open(fname string) (*DbFile, error)

func OpenFrom

func OpenFrom(f io.ReadSeeker) (*DbFile, error)

func (*DbFile) Close

func (db *DbFile) Close() error

func (*DbFile) Dumpdb

func (db *DbFile) Dumpdb() error

func (*DbFile) Encoding

func (db *DbFile) Encoding() int

Encoding returns the text encoding for this database

func (*DbFile) NumPage

func (db *DbFile) NumPage() int

NumPage returns the number of pages for this database

func (*DbFile) PageSize

func (db *DbFile) PageSize() int

PageSize returns the database page size in bytes

func (*DbFile) Tables

func (db *DbFile) Tables() []Table

func (*DbFile) Version

func (db *DbFile) Version() int

Version returns the sqlite version number used to create this database

func (*DbFile) VisitTableRecords

func (db *DbFile) VisitTableRecords(tableName string, f func(*int64, Record) error) error

VisitTableRecords performs an inorder traversal of all cells in the btree for the table with the given name, passing the (optional, hence nullable) RowID, and record-decoded payload of each cell to the visitor function `f`.

type PageKind

type PageKind byte

PageKind describes what kind of page is.

func (PageKind) String

func (pk PageKind) String() string

type Record

type Record struct {
	Header RecordHeader
	Body   []byte
	Values []interface{}
}

type RecordHeader

type RecordHeader struct {
	Len   int
	Types []SerialType
}

type SerialType

type SerialType int

SerialType represents SQLite types on disk

const (
	StNull SerialType = iota
	StInt8
	StInt16
	StInt24
	StInt32
	StInt48
	StInt64
	StFloat
	StC0
	StC1

	StBlob SerialType = 12
	StText            = 13
)

func (SerialType) IsBlob

func (st SerialType) IsBlob() bool

func (SerialType) IsText

func (st SerialType) IsText() bool

func (SerialType) NBytes

func (st SerialType) NBytes() int

NBytes returns the number of bytes on disk for this SerialType NBytes returns -1 if the SerialType is invalid.

func (SerialType) String

func (st SerialType) String() string

type Table

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

Table is a SQLite table

func (*Table) Columns

func (t *Table) Columns() []Column

Columns returns the columns of the table

func (*Table) Name

func (t *Table) Name() string

Name returns the name of the table

func (*Table) NumRow

func (t *Table) NumRow() int64

NumRow returns the number of rows in the table

Directories

Path Synopsis
cmd
sqlite-dump
Command sqlite-dump is a simple command that dumps the high-level content of a SQLITE3 file on screen.
Command sqlite-dump is a simple command that dumps the high-level content of a SQLITE3 file on screen.

Jump to

Keyboard shortcuts

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