Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use in-memory storage for browser environments
- Loading branch information
Showing
4 changed files
with
37 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// +build !js | ||
|
||
package db | ||
|
||
import "github.com/syndtr/goleveldb/leveldb" | ||
|
||
// Open creates a new database using the given file path for permanent storage. | ||
// It is not safe to have multiple DBs using the same file path. | ||
func Open(path string) (*DB, error) { | ||
ldb, err := leveldb.OpenFile(path, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &DB{ | ||
ldb: ldb, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// +build js,wasm | ||
|
||
package db | ||
|
||
import ( | ||
"github.com/syndtr/goleveldb/leveldb" | ||
"github.com/syndtr/goleveldb/leveldb/storage" | ||
) | ||
|
||
// Open creates a new database using in-memory storage. The given file path is | ||
// ignored. | ||
func Open(path string) (*DB, error) { | ||
ldb, err := leveldb.Open(storage.NewMemStorage(), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &DB{ | ||
ldb: ldb, | ||
}, nil | ||
} |