git.iko.soy/rowtype-yoga/purescript-yoga-sqlite
on main help sign in
commitfa4fdffa711a11ccf2378a696e4fe1b7835262d9 authorMark <mark.eibes@gmail.com> dateFri 20 Feb 2026, 21:55 (7 months ago) parentbaf2d5f
3 files changed+34−5
src/Yoga/SQLite/SQLite.purs+10−1 src/Yoga/SQLite/Schema.purs+3−2 test/Main.purs+21−2
src/Yoga/SQLite/SQLite.purs+10−1
@@ -2,6 +2,7 @@ module Yoga.SQLite.SQLite where
22
33import Prelude
44
5+import Data.DateTime (DateTime)
56import Data.Maybe (Maybe(..))
67import Data.Newtype (class Newtype)
78import Data.Nullable (Nullable, toNullable)
@@ -55,7 +56,10 @@ instance ToSQLiteValue BigInt where
5556 toSQLiteValue = unsafeCoerce
5657
5758instance ToSQLiteValue Boolean where
58− toSQLiteValue = unsafeCoerce
59+ toSQLiteValue b = unsafeCoerce (if b then 1 else 0)
60+
61+instance ToSQLiteValue DateTime where
62+ toSQLiteValue dt = unsafeCoerce (dateTimeToStringImpl (JSDate.fromDateTime dt))
5963
6064instance ToSQLiteValue a => ToSQLiteValue (Maybe a) where
6165 toSQLiteValue = case _ of
@@ -249,6 +253,11 @@ migrate stmts conn =
249253
250254data TransactionMode = Write | Read | Deferred
251255
256+derive instance Eq TransactionMode
257+
258+instance Show TransactionMode where
259+ show = transactionModeToString
260+
252261transactionModeToString :: TransactionMode -> String
253262transactionModeToString = case _ of
254263 Write -> "write"
src/Yoga/SQLite/Schema.purs+3−2
@@ -539,8 +539,8 @@ else instance IsAutoGenerated a => IsAutoGenerated (Unique a) where
539539 isAutoGenerated _ = isAutoGenerated (Proxy :: Proxy a)
540540else instance IsAutoGenerated a => IsAutoGenerated (ForeignKey t r c a) where
541541 isAutoGenerated _ = isAutoGenerated (Proxy :: Proxy a)
542−else instance IsAutoGenerated a => IsAutoGenerated (RandomRowId a) where
543− isAutoGenerated _ = isAutoGenerated (Proxy :: Proxy a)
542+else instance IsAutoGenerated (RandomRowId a) where
543+ isAutoGenerated _ = true
544544else instance IsAutoGenerated a => IsAutoGenerated (Nullable a) where
545545 isAutoGenerated _ = isAutoGenerated (Proxy :: Proxy a)
546546else instance IsAutoGenerated a where
@@ -2799,6 +2799,7 @@ else instance IsAutoGeneratedTC (DefaultExpr expr a) True
27992799else instance IsAutoGeneratedTC a result => IsAutoGeneratedTC (PrimaryKey a) result
28002800else instance IsAutoGeneratedTC a result => IsAutoGeneratedTC (Unique a) result
28012801else instance IsAutoGeneratedTC a result => IsAutoGeneratedTC (ForeignKey t r c a) result
2802+else instance IsAutoGeneratedTC (RandomRowId a) True
28022803else instance IsAutoGeneratedTC a result => IsAutoGeneratedTC (Nullable a) result
28032804else instance IsAutoGeneratedTC a False
28042805
test/Main.purs+21−2
@@ -106,7 +106,7 @@ f64DocsTable :: Proxy F64DocsTable
106106f64DocsTable = Proxy
107107
108108type RandomRowIdTable = Table "things"
109− ( id :: Int # PrimaryKey # AutoIncrement # RandomRowId
109+ ( id :: Int # PrimaryKey # RandomRowId
110110 , name :: String
111111 )
112112
@@ -686,10 +686,29 @@ spec = before setupConn do
686686 let actives = map (\r -> r.active) (rows :: Array { id :: Int, active :: SQLiteBool, role :: String, score :: Int })
687687 actives `shouldEqual` [SQLiteBool false]
688688
689+ it "RandomRowId column excluded from typed insert" \conn -> do
690+ SQLite.executeSimple (SQLite.SQL (createTableDDL @RandomRowIdTable)) conn # void
691+ runExecute conn {} (from (Proxy :: Proxy RandomRowIdTable) # insert { name: "hello" }) # void
692+ rows <- runQuery conn {} (from (Proxy :: Proxy RandomRowIdTable) # select @"name")
693+ let names = map (_.name) (rows :: Array { name :: String })
694+ names `shouldEqual` ["hello"]
695+
696+ it "DateTime as SQLiteValue in batch" \conn -> do
697+ SQLite.executeSimple (SQLite.SQL (createTableDDL @EventsTable)) conn # void
698+ SQLite.execute
699+ (SQLite.SQL "INSERT INTO events (title, metadata, created_at) VALUES (?1, ?2, ?3)")
700+ [ SQLite.toSQLiteValue "test"
701+ , SQLite.toSQLiteValue "{}"
702+ , SQLite.toSQLiteValue testDateTime
703+ ]
704+ conn # void
705+ rows <- runQuery conn {} (from eventsTable # selectAll)
706+ Array.length rows `shouldEqual` 1
707+
689708 describe "DDL RANDOM ROWID" do
690709 it "generates DDL with RANDOM ROWID suffix" \_ -> do
691710 let result = createTableDDL @RandomRowIdTable
692− result `shouldEqual` "CREATE TABLE things (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL) RANDOM ROWID"
711+ result `shouldEqual` "CREATE TABLE things (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL) RANDOM ROWID"
693712
694713 describe "DDL F64Vector" do
695714 it "createTableDDL with F64Vector" \_ -> do