Allow expressions as column default values

Open
#829 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
sqlite, swift
Domain
database

Research direction

Start at the tableColumn.column API shown in the example and trace how its defaultValue is incorporated into the generated CREATE TABLE statement. Reproduce the reported datetime default case and verify that an expression such as (datetime('now', 'localtime')) is emitted as valid SQLite SQL.

Written by the indexing model from the issue text.

Description

enhancement

Hey everyone,

I have a problem with create table.
I have tested create a new table with a column that creates automatically DateTime.

CREATE TABLE test (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT,
  t REAL DEFAULT (datetime('now', 'localtime'))
);

insert into test ('name') values ('Lucas')

"1" "Lucas" "2018-08-01 11:07:49"

I've tried to do this way, it doesn't work though.

let exp = Expression<String>("created_at")
tableColumn.column(exp, defaultValue: "(datetime('now', 'localtime'))")

near ""created_at"": syntax error (code: 1)

Dominant language
Swift
Stars
10.2k
Forks
1.6k
Avg merge
6d 2h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stephencelis/SQLite.swift

All issues in stephencelis/SQLite.swift

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.