go-sqlcipher icon indicating copy to clipboard operation
go-sqlcipher copied to clipboard

Upgrade sqlite3 to the latest version.

Open oSethoum opened this issue 3 years ago • 8 comments

This package is using a the version 3.30.1 from sqlite3 which doesn't support RETURNING that a lot of orms use when creating new record in the database, I tried forking the package and using the upgrade script, but the pragma key is no longer working. image

oSethoum avatar Oct 06 '22 18:10 oSethoum

You may want to have a look at: https://github.com/ValentinMontmirail/go-sqlcipher I just updated to SQLite 3.45.0 (This pre-release for now)

ValentinMontmirail avatar Dec 17 '23 14:12 ValentinMontmirail

@ValentinMontmirail Thank you, I will try it out soon and give you feedback.

oSethoum avatar Dec 17 '23 19:12 oSethoum

@ValentinMontmirail I cloned your repo locally and replaced the dependency, the issue is the database file doesn't get encrypted, am using it with ent like this

var Client *ent.Client

func Init() {
	client, err := ent.Open("sqlite3", "file:ent.sqlite?_key=secret&cache=shared&_fk=1")
	if err != nil {
		log.Fatalf("failed opening connection to sqlite: %v", err)
	}

	if err := client.Schema.Create(context.Background()); err != nil {
		log.Fatalf("failed creating schema resources: %v", err)
	}

	Client = client
}

the database file can be viewed.

image

oSethoum avatar Dec 17 '23 20:12 oSethoum

That's odd. I will have a look. Thanks for the feedback !

ValentinMontmirail avatar Dec 18 '23 07:12 ValentinMontmirail

@ValentinMontmirail maybe am doing it wrong, if so, please provide an example that I can use.

oSethoum avatar Dec 18 '23 08:12 oSethoum

Should be better now. Can you retry with github.com/ValentinMontmirail/go-sqlcipher v0.0.0-20231219102833-c47b144b2843 ?

ValentinMontmirail avatar Dec 19 '23 11:12 ValentinMontmirail

@ValentinMontmirail same thing, can you publish an example? maybe am doing something wrong.

oSethoum avatar Dec 19 '23 16:12 oSethoum

small-Example.zip

You will find in attachment, a very small example where the *sql.DB object generated after encryption can be used by an ORM. Basically, it uses automatically-generated type-safe interfaces for your queries.

There is also a Docker image on alpine to make it run safely.

ValentinMontmirail avatar Dec 19 '23 21:12 ValentinMontmirail