Skip to content

Commit 0689196

Browse files
committed
Updated sqobjects
1 parent e6bc911 commit 0689196

32 files changed

+363
-1327
lines changed

cmd/sqaccess/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
// Namespace Imports
7+
//. "github.com/djthorpe/go-sqlite"
8+
9+
// Modules
10+
"github.com/djthorpe/go-sqlite/pkg/sqobj"
11+
)
12+
13+
////////////////////////////////////////////////////////////////////////////////
14+
// TYPES
15+
16+
type User struct {
17+
Name string `sqlite:"name,primary"`
18+
Hash string `sqlite:"hash,not null"`
19+
}
20+
21+
func main() {
22+
fmt.Println("IN")
23+
if r, err := sqobj.NewReflect(User{}); err != nil {
24+
fmt.Println(err)
25+
} else {
26+
fmt.Println(r)
27+
}
28+
}

cmd/sqtool/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func main() {
5555
}
5656
defer db.Close()
5757

58-
db.SetTraceHook(trace, sqlite3.SQLITE_TRACE_PROFILE)
58+
//db.SetTraceHook(trace, sqlite3.SQLITE_TRACE_PROFILE)
5959

6060
// Report on the database
6161
log.Println("database:", db.Filename(sqlite3.DefaultSchema))

npm/sqlite3/html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h1 class="_name">[schema]</h1>
4545
</ul>
4646
<!-- TABLE CONTENT (TableView) -->
4747
<div class="m-2">
48-
<table-view id="results" data-class="table-hover table-sm table-striped" data-columns="Col A, Col B, Col D" data-rows="4"></table-view>
48+
<table-view cols="Col A, Col B, Col C"></table-view>
4949
</div>
5050
</div>
5151
<div class="col-md-2 d-md-block d-none bg-light border-start" id="database">

npm/sqlite3/js/index.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,9 @@ import '../css/index.css';
66
import App from './controller/app';
77

88
// Views
9-
import ComponentView from './view/component-view';
10-
import BadgeView from './view/badge-view';
11-
import TableView from './view/table-view';
12-
import TableHeadView from './view/table-head-view';
13-
import TableBodyView from './view/table-body-view';
14-
15-
// Define tag names
16-
ComponentView.define('badge-view', BadgeView);
17-
ComponentView.define('table-view', TableView);
18-
ComponentView.define('table-head-view', TableHeadView);
19-
ComponentView.define('table-body-view', TableBodyView);
9+
import './view/table-view';
10+
import './view/table-head-view';
11+
import './view/table-body-view';
2012

2113
// Import js-framework
2214
const jsf = require('@djthorpe/js-framework');
@@ -29,4 +21,3 @@ window.addEventListener('DOMContentLoaded', () => {
2921
console.log('Running application', app.constructor.name);
3022
app.main();
3123
});
32-

npm/sqlite3/package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/sqlite3/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"dist/**/*.{js,map,woff,woff2,txt,ttf,css,html,jpg,jpeg,png,gif,svg}"
4141
],
4242
"dependencies": {
43-
"@djthorpe/js-framework": "^0.0.47"
43+
"@djthorpe/js-framework": "^0.0.47",
44+
"lit-html": "^1.4.1"
4445
}
4546
}

pkg/quote/quote.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ func QuoteIdentifiers(v ...string) string {
4545
if len(v) == 1 {
4646
return QuoteIdentifier(v[0])
4747
}
48+
result := make([]string, len(v))
4849
for i, v_ := range v {
49-
v[i] = QuoteIdentifier(v_)
50+
result[i] = QuoteIdentifier(v_)
5051
}
51-
return strings.Join(v, ",")
52+
return strings.Join(result, ",")
5253
}
5354

5455
// QuoteDeclType returns a supported type or quotes type

pkg/sqlite3/auth.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
// PRIVATE FUNCTIONS
1616

1717
func (p *Pool) auth(ctx context.Context, action sqlite3.SQAction, args [4]string) error {
18-
//fmt.Printf("auth %v %q\n", action, args)
1918
switch action {
2019
case sqlite3.SQLITE_CREATE_INDEX:
2120
return p.Auth.CanExec(ctx, SQLITE_AUTH_INDEX|SQLITE_AUTH_CREATE, args[2], args[1], args[0])

pkg/sqlite3/cache_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ import (
1919

2020
func Test_Cache_001(t *testing.T) {
2121
// Create a connection and enable the connection cache (which caches prepared statements)
22-
conn, err := OpenPath(":memory:", sqlite3.DefaultFlags|sqlite3.SQLITE_OPEN_CONNCACHE)
22+
conn, err := OpenPath(":memory:", SQFlag(sqlite3.DefaultFlags)|SQLITE_OPEN_CACHE)
2323
if err != nil {
2424
t.Fatal(err)
2525
}
26-
defer conn.Close()
2726

2827
// Perform caching in a transaction
2928
conn.Do(context.Background(), 0, func(txn SQTransaction) error {

pkg/sqlite3/conn.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Conn struct {
2525
ConnCache
2626

2727
c chan struct{}
28+
f SQFlag
2829
ctx context.Context
2930
}
3031

@@ -38,11 +39,24 @@ type TxnFunc func(SQTransaction) error
3839
////////////////////////////////////////////////////////////////////////////////
3940
// LIFECYCLE
4041

41-
func OpenPath(path string, flags sqlite3.OpenFlags) (*Conn, error) {
42+
// New creates an in-memory database. Pass any flags to set open options. If
43+
// no flags are provided, the default is to create a read/write database.
44+
func New(flags ...SQFlag) (*Conn, error) {
45+
f := SQFlag(0)
46+
if len(flags) == 0 {
47+
f |= SQFlag(sqlite3.DefaultFlags)
48+
}
49+
for _, flag := range flags {
50+
f |= flag
51+
}
52+
return OpenPath(defaultMemory, f)
53+
}
54+
55+
func OpenPath(path string, flags SQFlag) (*Conn, error) {
4256
conn := new(Conn)
4357

4458
// If no create flag then check to make sure database exists
45-
if path != defaultMemory && flags&sqlite3.SQLITE_OPEN_CREATE == 0 {
59+
if path != defaultMemory && flags&SQFlag(sqlite3.SQLITE_OPEN_MEMORY) == 0 && SQFlag(sqlite3.SQLITE_OPEN_CREATE) == 0 {
4660
if _, err := os.Stat(path); os.IsNotExist(err) {
4761
return nil, ErrNotFound.Withf("%q", path)
4862
} else if err != nil {
@@ -51,14 +65,15 @@ func OpenPath(path string, flags sqlite3.OpenFlags) (*Conn, error) {
5165
}
5266

5367
// Open database with flags
54-
if c, err := sqlite3.OpenPathEx(path, flags, ""); err != nil {
68+
if c, err := sqlite3.OpenPathEx(path, sqlite3.OpenFlags(flags), ""); err != nil {
5569
return nil, err
5670
} else {
5771
conn.ConnEx = c
72+
conn.f = flags
5873
}
5974

6075
// Set cache to default size
61-
if flags&sqlite3.SQLITE_OPEN_CONNCACHE != 0 {
76+
if flags&SQLITE_OPEN_CACHE != 0 {
6277
conn.SetCap(defaultCapacity)
6378
} else {
6479
conn.SetCap(0)
@@ -97,7 +112,7 @@ func (conn *Conn) Exec(st SQStatement, fn ExecFunc) error {
97112
}
98113

99114
// Perform a transaction, rollback if error is returned
100-
func (conn *Conn) Do(ctx context.Context, flag SQTxnFlag, fn func(SQTransaction) error) error {
115+
func (conn *Conn) Do(ctx context.Context, flag SQFlag, fn func(SQTransaction) error) error {
101116
conn.Mutex.Lock()
102117
defer conn.Mutex.Unlock()
103118

@@ -117,7 +132,7 @@ func (conn *Conn) Do(ctx context.Context, flag SQTxnFlag, fn func(SQTransaction)
117132
}
118133
}
119134

120-
// Flags
135+
// Transaction flags
121136
v := sqlite3.SQLITE_TXN_DEFAULT
122137
if flag.Is(SQLITE_TXN_EXCLUSIVE) {
123138
v = sqlite3.SQLITE_TXN_EXCLUSIVE
@@ -185,3 +200,8 @@ func (txn *Txn) Query(st SQStatement, v ...interface{}) (SQResults, error) {
185200
return r, nil
186201
}
187202
}
203+
204+
// Flags returns the Open Flags
205+
func (c *Conn) Flags() SQFlag {
206+
return c.f
207+
}

0 commit comments

Comments
 (0)