https://github.com/0xf6da/sqlite.ahk
AHKv2: better-sqlite3 with only db.prepare() and stmt.all(); supports named parameters
https://github.com/0xf6da/sqlite.ahk
autohotkey autohotkey-v2 better-sqlite3 sqlite
Last synced: about 1 year ago
JSON representation
AHKv2: better-sqlite3 with only db.prepare() and stmt.all(); supports named parameters
- Host: GitHub
- URL: https://github.com/0xf6da/sqlite.ahk
- Owner: 0xf6da
- Created: 2024-10-27T05:51:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-27T05:53:26.000Z (over 1 year ago)
- Last Synced: 2025-02-13T01:36:05.703Z (over 1 year ago)
- Topics: autohotkey, autohotkey-v2, better-sqlite3, sqlite
- Language: AutoHotkey
- Homepage:
- Size: 1.24 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
sqlite but with only prepared statements
```ahk
#Include %A_LineFile%/../sqlite.ahk
db:=sqlite(":memory:", A_LineFile "\..\sqlite3.dll") ;path to sqlite3.dll is needed
; ":memory:" is temporary, use a filename for persistent storage
; normal usage:
; db:=sqlite("db.sqlite", A_LineFile "\..\sqlite3.dll")
db.prepare("
(
CREATE TABLE debts (
DebtName TEXT,
Amount TEXT,
CreatedDate TEXT
`)
)").all() ;create table using prepared statement
view_db() {
static select_statement := db.prepare("select DebtName,Amount,CreatedDate from debts")
rows:=select_statement.all() ;Array
for row in rows {
OutputDebug row.DebtName ": " row.Amount "`n"
; works too:
; OutputDebug row["DebtName"] ": " row["Amount"] "`n"
; works too: (useful for when you don't know the name of the column)
; OutputDebug row[1] ": " row[2] "`n"
; for k,v in row { ; Enumerator gives you column names (and values)
; OutputDebug k ": " v "`n"
; }
}
}
;Array mode: indexed params ("?" , "?NNN")
db.prepare("insert into debts (DebtName,Amount,CreatedDate) VALUES (?,?,?)").all("Medical Bill",2000,"2024-08-25")
db.prepare("update debts set Amount=? where DebtName=?").all(1500,"Medical Bill")
view_db()
;Object mode: named params (":AAA", "@AAA", "$AAA")
db.prepare("update debts set Amount=$Amount where DebtName=$DebtName").all({Amount:1000,DebtName:"Medical Bill"}) ;using {} Object
view_db()
;Object mode: named params (":AAA", "@AAA", "$AAA")
db.prepare("update debts set Amount=:Amount where DebtName=:DebtName").all(Map("Amount",500,"DebtName","Medical Bill")) ;using Map() works too
view_db()
```
.loadExtension() is not supported but will be added on request, and more
better error messages is being worked on, any recommendation/error report is appreciated