Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: unknown selector #9

Open
ghost opened this issue Sep 3, 2018 · 4 comments
Open

Error: unknown selector #9

ghost opened this issue Sep 3, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Sep 3, 2018

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
Copy link
Author

ghost commented Sep 3, 2018

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 ghost closed this as completed Sep 3, 2018
@ghost
Copy link
Author

ghost commented Sep 3, 2018

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

@ghost ghost reopened this Sep 3, 2018
@Araq
Copy link
Owner

Araq commented Sep 3, 2018

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

@ghost
Copy link
Author

ghost commented Sep 3, 2018

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)
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant