-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.v
40 lines (37 loc) · 787 Bytes
/
main.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module main
import db.sqlite
import time
import os
import encoding.base64
struct Person {
id int [primary; sql: serial]
name string [nonull]
date_of_birth time.Time [sql_type: 'DATETIME']
address string
photo string [sql_type: 'BLOB']
}
fn main() {
mut db := sqlite.connect('persons.db')!
sql db {
create table Person
}!
image_path := 'ashraf.jpg'
image := os.read_bytes(image_path)!
image_base64 := base64.encode(image)
person := Person{
name: 'Ashraf'
date_of_birth: time.now()
photo: image_base64
address: 'Cairo'
}
sql db {
insert person into Person
}!
p := sql db {
select from Person
}!
image_bytes := base64.decode(p[0].photo)
mut f := os.create('copy.jpg')!
f.write(image_bytes)!
f.close()
}