Stop using NULL in the database

It's simply easier not to with the stock SQL engine
This commit is contained in:
akp 2024-05-27 14:56:22 +01:00
parent c0d3cc0416
commit 60dbcab706
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755
2 changed files with 8 additions and 8 deletions

View file

@ -10,7 +10,7 @@ SQLITEFILE = sys.argv[2]
with open(CSVFILE) as csvf:
csv_reader = csv.reader(csvf)
x = list(map(lambda x: (str(uuid.uuid4()), *map(lambda y: (y if y != "" else None), x)), list(csv_reader)[1:]))
x = list(map(lambda x: (str(uuid.uuid4()), *map(lambda y: (y if y != "" else ""), x)), list(csv_reader)[1:]))
db = sqlite3.connect(SQLITEFILE)
db.executemany(
"""INSERT INTO articles("id", "url", "title", "description", "image_url", "date", "hacker_news_url") VALUES (?, ?, ?, ?, ?, ?, ?)""",

View file

@ -1,20 +1,20 @@
package models
import (
"time"
"github.com/google/uuid"
"time"
)
type NewArticle struct {
URL string `validate:"required,url"`
Title string `validate:"required"`
Description string `db:"description,nullzero"`
ImageURL string `db:"image_url,nullzero"`
Date time.Time `validate:"required"`
URL string `validate:"required,url"`
Title string `validate:"required"`
Description string `db:"description"`
ImageURL string `db:"image_url"`
Date time.Time `validate:"required"`
}
type Article struct {
NewArticle
ID uuid.UUID
HackerNewsURL string `db:"hacker_news_url,nullzero"`
HackerNewsURL string `db:"hacker_news_url"`
}