...

Source file src/github.com/go-kivik/kivik/v4/x/fsdb/db.go

Documentation: github.com/go-kivik/kivik/v4/x/fsdb

     1  // Licensed under the Apache License, Version 2.0 (the "License"); you may not
     2  // use this file except in compliance with the License. You may obtain a copy of
     3  // the License at
     4  //
     5  //  http://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     9  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    10  // License for the specific language governing permissions and limitations under
    11  // the License.
    12  
    13  package fs
    14  
    15  import (
    16  	"context"
    17  	"errors"
    18  	"net/http"
    19  	"os"
    20  	"path/filepath"
    21  
    22  	"github.com/go-kivik/kivik/v4/driver"
    23  	"github.com/go-kivik/kivik/v4/x/fsdb/cdb"
    24  	"github.com/go-kivik/kivik/v4/x/fsdb/filesystem"
    25  )
    26  
    27  type db struct {
    28  	*client
    29  	dbPath, dbName string
    30  	fs             filesystem.Filesystem
    31  	cdb            *cdb.FS
    32  }
    33  
    34  var _ driver.DB = &db{}
    35  
    36  var notYetImplemented = statusError{status: http.StatusNotImplemented, error: errors.New("kivik: not yet implemented in fs driver")}
    37  
    38  func (d *db) path(parts ...string) string {
    39  	return filepath.Join(append([]string{d.dbPath}, parts...)...)
    40  }
    41  
    42  func (d *db) AllDocs(context.Context, driver.Options) (driver.Rows, error) {
    43  	// FIXME: Unimplemented
    44  	return nil, notYetImplemented
    45  }
    46  
    47  func (d *db) Query(context.Context, string, string, driver.Options) (driver.Rows, error) {
    48  	// FIXME: Unimplemented
    49  	return nil, notYetImplemented
    50  }
    51  
    52  func (d *db) Delete(context.Context, string, driver.Options) (newRev string, err error) {
    53  	// FIXME: Unimplemented
    54  	return "", notYetImplemented
    55  }
    56  
    57  func (d *db) Stats(context.Context) (*driver.DBStats, error) {
    58  	_, err := d.fs.Stat(d.path())
    59  	if err != nil {
    60  		if errors.Is(err, os.ErrNotExist) {
    61  			return nil, &statusError{status: http.StatusNotFound, error: err}
    62  		}
    63  		return nil, err
    64  	}
    65  	return &driver.DBStats{
    66  		Name:           d.dbName,
    67  		CompactRunning: false,
    68  	}, nil
    69  }
    70  
    71  func (d *db) CompactView(context.Context, string) error {
    72  	// FIXME: Unimplemented
    73  	return notYetImplemented
    74  }
    75  
    76  func (d *db) ViewCleanup(context.Context) error {
    77  	// FIXME: Unimplemented
    78  	return notYetImplemented
    79  }
    80  
    81  func (d *db) BulkDocs(context.Context, []interface{}) ([]driver.BulkResult, error) {
    82  	// FIXME: Unimplemented
    83  	return nil, notYetImplemented
    84  }
    85  
    86  func (d *db) PutAttachment(context.Context, string, *driver.Attachment, driver.Options) (string, error) {
    87  	// FIXME: Unimplemented
    88  	return "", notYetImplemented
    89  }
    90  
    91  func (d *db) GetAttachment(context.Context, string, string, driver.Options) (*driver.Attachment, error) {
    92  	// FIXME: Unimplemented
    93  	return nil, notYetImplemented
    94  }
    95  
    96  func (d *db) DeleteAttachment(context.Context, string, string, driver.Options) (newRev string, err error) {
    97  	// FIXME: Unimplemented
    98  	return "", notYetImplemented
    99  }
   100  
   101  func (d *db) Close() error {
   102  	return nil
   103  }
   104  

View as plain text