@@ -8,13 +8,14 @@ import (
88 "encoding/json"
99 "errors"
1010 "fmt"
11- "github.com/tursodatabase/libsql-client-go/sqliteparserutils"
1211 "io"
1312 "net/http"
1413 net_url "net/url"
1514 "runtime/debug"
1615 "strings"
1716
17+ "github.com/tursodatabase/libsql-client-go/sqliteparserutils"
18+
1819 "github.com/tursodatabase/libsql-client-go/libsql/internal/hrana"
1920 "github.com/tursodatabase/libsql-client-go/libsql/internal/http/shared"
2021)
@@ -36,8 +37,8 @@ func init() {
3637 commitHash = "unknown"
3738}
3839
39- func Connect (url , jwt , host string , schemaDb bool ) driver.Conn {
40- return & hranaV2Conn {url , jwt , host , schemaDb , "" , false , 0 }
40+ func Connect (url , jwt , host string , schemaDb bool , encryptionKey string ) driver.Conn {
41+ return & hranaV2Conn {url , jwt , host , schemaDb , encryptionKey , "" , false , 0 }
4142}
4243
4344type hranaV2Stmt struct {
@@ -82,13 +83,14 @@ func (s *hranaV2Stmt) QueryContext(ctx context.Context, args []driver.NamedValue
8283}
8384
8485type hranaV2Conn struct {
85- url string
86- jwt string
87- host string
88- schemaDb bool
89- baton string
90- streamClosed bool
91- replicationIndex uint64
86+ url string
87+ jwt string
88+ host string
89+ schemaDb bool
90+ remoteEncryptionKey string
91+ baton string
92+ streamClosed bool
93+ replicationIndex uint64
9294}
9395
9496func (h * hranaV2Conn ) Ping () error {
@@ -121,11 +123,11 @@ func (h *hranaV2Conn) PrepareContext(ctx context.Context, query string) (driver.
121123
122124func (h * hranaV2Conn ) Close () error {
123125 if h .baton != "" {
124- go func (baton , url , jwt , host string ) {
126+ go func (baton , url , jwt , host , encryptionKey string ) {
125127 msg := hrana.PipelineRequest {Baton : baton }
126128 msg .Add (hrana .CloseStream ())
127- _ , _ , _ = sendPipelineRequest (context .Background (), & msg , url , jwt , host )
128- }(h .baton , h .url , h .jwt , h .host )
129+ _ , _ , _ = sendPipelineRequest (context .Background (), & msg , url , jwt , host , encryptionKey )
130+ }(h .baton , h .url , h .jwt , h .host , h . remoteEncryptionKey )
129131 }
130132 return nil
131133}
@@ -173,7 +175,7 @@ func (h *hranaV2Conn) sendPipelineRequest(ctx context.Context, msg *hrana.Pipeli
173175 if h .replicationIndex > 0 {
174176 addReplicationIndex (msg , h .replicationIndex )
175177 }
176- result , streamClosed , err := sendPipelineRequest (ctx , msg , h .url , h .jwt , h .host )
178+ result , streamClosed , err := sendPipelineRequest (ctx , msg , h .url , h .jwt , h .host , h . remoteEncryptionKey )
177179 if streamClosed {
178180 h .streamClosed = true
179181 }
@@ -230,7 +232,7 @@ func getReplicationIndex(response *hrana.PipelineResponse) uint64 {
230232 return replicationIndex
231233}
232234
233- func sendPipelineRequest (ctx context.Context , msg * hrana.PipelineRequest , url string , jwt string , host string ) (result hrana.PipelineResponse , streamClosed bool , err error ) {
235+ func sendPipelineRequest (ctx context.Context , msg * hrana.PipelineRequest , url string , jwt string , host string , remoteEncryptionKey string ) (result hrana.PipelineResponse , streamClosed bool , err error ) {
234236 reqBody , err := json .Marshal (msg )
235237 if err != nil {
236238 return hrana.PipelineResponse {}, false , err
@@ -247,6 +249,10 @@ func sendPipelineRequest(ctx context.Context, msg *hrana.PipelineRequest, url st
247249 req .Header .Set ("Authorization" , "Bearer " + jwt )
248250 }
249251 req .Header .Set ("x-libsql-client-version" , "libsql-remote-go-" + commitHash )
252+ if remoteEncryptionKey != "" {
253+ req .Header .Set ("x-turso-encryption-key" , remoteEncryptionKey )
254+ }
255+
250256 req .Host = host
251257 resp , err := http .DefaultClient .Do (req )
252258 if err != nil {
@@ -591,11 +597,11 @@ func (h *hranaV2Conn) QueryContext(ctx context.Context, query string, args []dri
591597
592598func (h * hranaV2Conn ) closeStream () {
593599 if h .baton != "" {
594- go func (baton , url , jwt , host string ) {
600+ go func (baton , url , jwt , host , encryptionKey string ) {
595601 msg := hrana.PipelineRequest {Baton : baton }
596602 msg .Add (hrana .CloseStream ())
597- _ , _ , _ = sendPipelineRequest (context .Background (), & msg , url , jwt , host )
598- }(h .baton , h .url , h .jwt , h .host )
603+ _ , _ , _ = sendPipelineRequest (context .Background (), & msg , url , jwt , host , encryptionKey )
604+ }(h .baton , h .url , h .jwt , h .host , h . remoteEncryptionKey )
599605 h .baton = ""
600606 }
601607}
0 commit comments