MCPcopy Index your code
hub / github.com/chuckpreslar/codex

github.com/chuckpreslar/codex @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
510 symbols 1,333 edges 66 files 297 documented · 58%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

codex

Codex is NOT an ORM, but a relation algebra inspired by Arel. Project is still under heavy development.

Build Status

Installation

With Google's Go installed on your machine:

$ go get -u github.com/chuckpreslar/codex

Usage

To show a little sample of what using Codex looks like, lets assume you have a table in your database (we'll call it users) and you want to select all the records it contains. The SQL looks a little like this:

SELECT "users".* FROM "users"

Now using Codex:

import (
  /* Maybe some other imports. */
  "github.com/chuckpreslar/codex"
)


users := codex.Table("users")
sql, err := users.ToSql()

Now that wasn't too bad, was it?

Selections

Projections

// ...

users := codex.Table("users")
sql, err := users.Project("id", "email", "first_name", "last_name").ToSql()

Filtering

// ...

users := codex.Table("users")
sql, err := users.Where(users("id").Eq(1).Or(users("email").Eq("test@example.com"))).ToSql()

Joins

// ...

users := codex.Table("users")
orders := codex.Table("orders")
sql, err := users.InnerJoin(orders).On(orders("user_id").Eq(users("id"))).ToSql()

// SELECT "users".* FROM "users" INNER JOIN "orders" ON "orders"."user_id" = "users"."id"

Insertions

// ...

sql, err := users.Insert("Jon", "Doe", "jon@example.com").
    Into("first_name", "last_name", "email").ToSql()

// INSERT INTO "users" ("first_name", "last_name", "email") VALUES ('Jon', 'Doe', 'jon@example.com')

Modifications

// ...

sql, err := users.Set("first_name", "last_name", "email").
    To("Jon", "Doe", "jon@example.com").
    Where(users("id").Eq(1)).ToSql()

// UPDATE "users" SET "first_name" = 'Jon', "last_name" = 'Doe', "email" = 'jon@example.com'
// WHERE "users"."id" = 1

Deletions

// ...

sql, err := users.Delete(users("id").Eq(1)).ToSql()

// DELETE FROM "users" WHERE "users"."id" = 1

Creations

The codex package currently provides a few common SQL data and constraint types as constants to use with creating and altering tables.

Constraints

  • NOT_NULL
  • UNIQUE
  • PRIMARY_KEY
  • FOREIGN_KEY
  • CHECK
  • DEFAULT

Types

  • STRING
  • TEXT
  • BOOLEAN
  • INTEGER
  • FLOAT
  • DECIMAL
  • DATE
  • TIME
  • DATETIME
  • TIMESTAMP
// ...

users := codex.CreateTable("users").
  AddColumn("first_name", codex.STRING).
  AddColumn("last_name", codex.STRING).
  AddColumn("email", codex.STRING).
  AddColumn("id", codex.INTEGER).
  AddConstraint("first_name", codex.NOT_NULL).
  AddConstraint("id", codex.PRIMARY_KEY).
  AddConstraint("email", codex.UNIQUE, "users_uniq_email") // Optional last argument supplies index name.

sql, err := users.ToSql()

// CREATE TABLE "users" ();
// ALTER TABLE "users" ADD "first_name" character varying(255);
// ALTER TABLE "users" ADD "last_name" character varying(255);
// ALTER TABLE "users" ADD "email" character varying(255);
// ALTER TABLE "users" ADD "id" integer;
// ALTER TABLE "users" ALTER "first_name" SET NOT NULL;
// ALTER TABLE "users" ADD PRIMARY KEY("id");
// ALTER TABLE "users" ADD CONSTRAINT "users_email_uniq" UNIQUE("email");

Alterations

Alterations work the same as Creations, only the the initializer function AlterTable is used in place of CreateTable.

Documentation

View godoc or visit godoc.org.

$ godoc codex

License

The MIT License (MIT)

Copyright (c) 2013 Chuck Preslar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Extension points exported contracts — how you extend this code

Accessor (FuncType)
Accessor is a type def of a function that returns an AttributeNode
managers/accessor.go
VisitorInterface (Interface)
(no doc) [1 implementers]
visitors/visitor_interface.go

Core symbols most depended-on inside this repo

Visit
called by 100
visitors/visitor_interface.go
Accept
called by 65
visitors/visitor_interface.go
Relation
called by 42
managers/accessor.go
Grouping
called by 40
nodes/grouping.go
Or
called by 24
nodes/or.go
And
called by 24
nodes/or.go
And
called by 20
nodes/and.go
Or
called by 20
nodes/or.go

Shape

Method 285
Function 153
TypeAlias 48
Struct 22
FuncType 1
Interface 1

Languages

Go100%

Modules by API surface

visitors/visitor_interface.go64 symbols
visitors/to_sql_visitor.go64 symbols
test/visitors/to_sql_visitors_test.go56 symbols
nodes/unary.go25 symbols
nodes/binary.go19 symbols
managers/select_manager.go17 symbols
managers/accessor.go15 symbols
nodes/constraint_node.go14 symbols
nodes/attribute.go14 symbols
nodes/sum.go12 symbols
nodes/minimum.go12 symbols
nodes/maximum.go12 symbols

For agents

$ claude mcp add codex \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact