Skip to content

Commit 6553ff6

Browse files
committed
Updated
1 parent 95aa193 commit 6553ff6

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PLUGIN_DIR = $(wildcard plugin/*)
1515

1616
.PHONY: all server plugins dependencies mkdir clean
1717

18-
all: clean server plugins
18+
all: clean plugins server
1919

2020
server: dependencies mkdir
2121
@echo Build server

etc/server.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ plugins:
66

77
# HTTP Server parameters
88
httpserver:
9+
# Port to listen on. Can be a path to unix socket to serve through FastCGI
910
addr: :80
1011

11-
# Handlers for serving plugins
12+
# Handlers for serving plugins
1213
handlers:
1314
sqlite3:
14-
prefix: /
15+
# The sqlite3 plugin can be viewed at http://localhost/api/sqlite
16+
prefix: /api/sqlite
17+
# Requests are logged
1518
middleware:
1619
- log
1720

1821
sqlite3:
19-
# Databases to load and/or create
22+
# Databases to load and/or create. Only the 'main' database is required.
2023
databases:
2124
main: ":memory:"
22-
# Set trace to true to enable the ability to profile queries
25+
# Set create to true to allow databases which don't exist to be created.
26+
create: true
27+
# Set trace to true to enable the ability to profile queries. Profiling information
28+
# can be displayed through the API.
2329
trace: true
2430
# Set max number of connections that can be simultaneously opened
2531
max: 100
2632

27-

pkg/sqlite3/pool.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type PoolConfig struct {
2929
Max int64 `yaml:"max"` // The maximum number of connections in the pool
3030
Schemas map[string]string `yaml:"databases"` // Schema names mapped onto path for database file
3131
Trace bool `yaml:"trace"` // Profiling for statements
32+
Create bool `yaml:"create"` // When false, do not allow creation of new file-based databases
3233
Auth SQAuth // Authentication and Authorization interface
3334
Flags sqlite3.OpenFlags // Flags for opening connections
3435
}
@@ -54,6 +55,7 @@ var (
5455
defaultPoolConfig = PoolConfig{
5556
Max: 5,
5657
Trace: false,
58+
Create: true,
5759
Schemas: map[string]string{defaultSchema: defaultMemory},
5860
Flags: sqlite3.DefaultFlags | sqlite3.SQLITE_OPEN_SHAREDCACHE,
5961
}
@@ -90,6 +92,13 @@ func OpenPool(config PoolConfig, errs chan<- error) (*Pool, error) {
9092
config.Flags = defaultPoolConfig.Flags
9193
}
9294

95+
// Update create flag
96+
if config.Create {
97+
config.Flags |= sqlite3.SQLITE_OPEN_CREATE
98+
} else {
99+
config.Flags &^= sqlite3.SQLITE_OPEN_CREATE
100+
}
101+
93102
// Set up pool
94103
p.PoolConfig = config
95104
p.Pool = sync.Pool{New: func() interface{} {

plugin/sqlite3/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (p *plugin) Run(ctx context.Context, provider Provider) error {
6161
return err
6262
}
6363

64-
// Run until cancelled
64+
// Run until cancelled - print any errors from the connection pool
6565
FOR_LOOP:
6666
for {
6767
select {

0 commit comments

Comments
 (0)