Araq / ormin

Ormin -- An ORM for Nim.
MIT License
152 stars 18 forks source link

Error: unknown selector #9

Open ghost opened 6 years ago

ghost commented 6 years ago

I'm trying to compile a project using ormin, but I keep getting an error about an unknown selector: Error: unknown selector: feeds. The full project is here, and relevant code is as follows:

import ormin

importModel(DbBackend.sqlite, "site_model")
var db {.global.} = open("stuff.db", "", "", "")

proc addFeed*(feedName: string): void =
    #db.exec(sql"INSERT INTO feeds (feed_url) VALUES (?)", feedName)
    query:
        insert feeds("google")

The error is on line 10 of db.nim, which is the insert feeds("google") line. I can't figure out what the issue is since I can get this working just fine with regular db_sqlite. Am I doing something wrong?

ghost commented 6 years ago

Just read your blog and found

Interestingly, Ormin's DSL for generating SQL does not cover schema creations. It is assumed that you need to interface to some existing database. Well, that is not true for our example, so here is a short program that runs this script:

To import the model we need the ormin_importer tool:

nim c tools/ormin_importer
tools/ormin_importer examples/chat/chat_model.sql

running the importer worked like a charm.

ghost commented 6 years ago

I stand corrected, I must have been using an out-of-date binary.

Even with the importer, I still can't get the project to compile

Araq commented 6 years ago

Ok, well, please attach your "site_model" or a simplified version that has the same problem.

ghost commented 6 years ago

site_model.sql:

CREATE TABLE IF NOT EXISTS feeds (
  id INTEGER PRIMARY KEY,
  feed_url text NOT NULL
);

site_model.nim:

# Generated by ormin_importer. DO NOT EDIT.
import ormin

type
  Attr = object
    name: string
    tabIndex: int
    typ: DbTypekind
    key: int   # 0 nothing special,
               # +1 -- primary key
               # -N -- references attribute N
const tableNames = [
  "feeds"
]

const attributes = [
  Attr(name: "id", tabIndex: 0, typ: dbInt, key: 1),
  Attr(name: "feed_url", tabIndex: 0, typ: dbVarchar, key: 0)
]