GithubHelp home page GithubHelp logo

memwey / casbin-sqlx-adapter Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 10.0 23 KB

sqlx adapter for Casbin https://github.com/casbin/casbin

License: Apache License 2.0

Go 100.00%
casbin casbin-adapter sqlx

casbin-sqlx-adapter's Issues

Panic with using pgx

The second line in code causes panic:

opts := &sqlxadapter.AdapterOptions{
		DriverName: "pgx",
		DataSourceName: v.GetString("dsn"),
		TableName: "casbin_rule",
	}
a := sqlxadapter.NewAdapterFromOptions(opts)
panic: ERROR: syntax error at or near "`" (SQLSTATE 42601)

goroutine 1 [running]:
github.com/memwey/casbin-sqlx-adapter.(*Adapter).ensureTable(0xc000372820)
        /Users/vivek/work/pkg/mod/github.com/memwey/[email protected]/adapter.go:99 +0x115
github.com/memwey/casbin-sqlx-adapter.NewAdapterFromOptions(0xc000217f18, 0x18a9083)
        /Users/vivek/work/pkg/mod/github.com/memwey/[email protected]/adapter.go:168 +0x93
main.main()

The sql for casbin_rule table is not sqlite friendly.

The sql in here, breaks when trying to use it in sqlite3.

Below is the smallest change.

CREATE TABLE IF NOT EXISTS `casbin_rule` (
    `id` INTEGER,
    `p_type` VARCHAR(32) NOT NULL DEFAULT '',
    `v0` VARCHAR(255) NOT NULL DEFAULT '',
    `v1` VARCHAR(255) NOT NULL DEFAULT '',
    `v2` VARCHAR(255) NOT NULL DEFAULT '',
    `v3` VARCHAR(255) NOT NULL DEFAULT '',
    `v4` VARCHAR(255) NOT NULL DEFAULT '',
    `v5` VARCHAR(255) NOT NULL DEFAULT '',
    PRIMARY KEY (`id`)
);

Also, out the box, I have now learnt, sqlite doesnt care about VARCHAR and it is always TEXT.

Here is an example with sqlite checking

CREATE TABLE IF NOT EXISTS `casbin_rule` (
    `id` INTEGER,
    `p_type` VARCHAR(32) NOT NULL DEFAULT ''
    CHECK(
      typeof("p_type") = "text" AND
      length("p_type") <= 32
    ),
    `v0` VARCHAR(255) NOT NULL DEFAULT ''
    CHECK(
      typeof("v0") = "text" AND
      length("v0") <= 255
    ),
    `v1` VARCHAR(255) NOT NULL DEFAULT ''
    CHECK(
      typeof("v1") = "text" AND
      length("v1") <= 255
    ),
    `v2` VARCHAR(255) NOT NULL DEFAULT ''
    CHECK(
      typeof("v2") = "text" AND
      length("v2") <= 255
    ),
    `v3` VARCHAR(255) NOT NULL DEFAULT ''
    CHECK(
      typeof("v3") = "text" AND
      length("v3") <= 255
    ),
    `v4` VARCHAR(255) NOT NULL DEFAULT ''
    CHECK(
      typeof("v4") = "text" AND
      length("v4") <= 255
    ),
    `v5` VARCHAR(255) NOT NULL DEFAULT ''
    CHECK(
      typeof("v5") = "text" AND
      length("v5") <= 255
    ),
    PRIMARY KEY (`id`)
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.