v icon indicating copy to clipboard operation
v copied to clipboard

orm: where <field> == nil not work

Open enghitalo opened this issue 3 years ago • 3 comments

select from Task where updated_at == nil

module main

import db.sqlite

[table: 'task']
struct Task {
mut:
	id         int    [primary; sql: serial]
	a          string
	updated_at string
}

fn main() {
	mut db := sqlite.connect('database.db')!
	sql db {
		create table Task
	} or { panic('error on create table: ${err}') }

	mut task_model := Task{
		a: 'a'
	}

	sql db {
		insert task_model into Task
	}

	task_model = Task{
		updated_at: 'lala'
	}

	sql db {
		insert task_model into Task
	} or { panic('error on create table: ${err}') }

	tasks := sql db {
		select from Task where updated_at == nil
	}

	dump(tasks)
	db.close()!
}

from https://discord.com/channels/592103645835821068/700746775962714232/1004082565369569380

enghitalo avatar Jul 31 '22 20:07 enghitalo

https://www.sqlservercentral.com/articles/understanding-the-difference-between-is-null-and-null

enghitalo avatar Oct 22 '22 02:10 enghitalo

Screenshot_2022-10-21-23-40-06-366_com.discord.jpg

enghitalo avatar Oct 22 '22 02:10 enghitalo

Screenshot_2022-10-21-23-41-09-147_com.discord.jpg

enghitalo avatar Oct 22 '22 02:10 enghitalo