memwey / casbin-sqlx-adapter Goto Github PK
View Code? Open in Web Editor NEWsqlx adapter for Casbin https://github.com/casbin/casbin
License: Apache License 2.0
sqlx adapter for Casbin https://github.com/casbin/casbin
License: Apache License 2.0
It would be nice, if you could add a new constructor method to the adapter to re-use an existant sqlx.DB connection.
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 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`)
);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.